|
You could use CDatabase[^] class if you were using MFC. Search this site. There are plenty of examples.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
See rather Microsoft samples from SDK
|
|
|
|
|
Hi
I have an API function call that asks to send a TCHAR* as an argument and it will return a string on the TCHAR*
Instead of sending a TCHAR* i send it as a char array, like this
char array[12];
Now when i debug and look at it, i see
array[0] = A
array[1] = 0
array[2] = B
array[3] = 0
array[4] = C
array[5] = 0
So if am expecting an output string of "ABC". What am seeing is, everyother index in the array is set to "0".
Why's this happening?
Is it a problem with using char array in place of TCHAR?
How to use the TCHAR?
|
|
|
|
|
You should zero-terminate the string, I suppose, i.e.
array[6] = 0
array[7] = 0
Nevermind, I was a it hasty.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, October 8, 2009 1:55 PM
|
|
|
|
|
Not quite, he's sending a char* which gets filled with TCHARs. It's the old Unicode <--> ASCII confusion again! Do people not read the manuals anymore?
|
|
|
|
|
Richard,
Can you tell me how to fix this issue?
|
|
|
|
|
You're right, of course. Too much drugz, today...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Too much drugz, today
Luckeee!
|
|
|
|
|
When i try to write the "array" string into a file, all that it writes is "A", and its ignoring the remaining array indexes.
Can this be solved by null terminating?
How to do that?
|
|
|
|
|
dipuks wrote: Can this be solved by null terminating?
The short answer is, no!
You need to understand the difference between TCHAR (Unicode, 16 bit) and ASCII (8-bit) characters. You cannot store a TCHAR string into a char[] array and expect the program to make sense of it. From the small piece of code you posted you just need to define your array as TCHAR[] and use the appropriate function calls to process the text.
Take a look here in MSDN[^] for some more information.
|
|
|
|
|
Richard MacCutchan wrote: You need to understand the difference between TCHAR (Unicode, 16 bit) and ASCII (8-bit) characters.
TCHAR is not an Unicode character. TCHAR is defined either as an Unicode character (wchar_t ) or an ASCII character (char ), depending on the build.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: TCHAR is defined either as
Quite correct. However, I was trying to keep it simple(r) as he was obviously putting Unicode characters into the array.
|
|
|
|
|
Hi,
You are doing an Unicode build (have defined _UNICODE instead of _MBCS ) and therefore TCHAR behaves like wchar_t (double byte character). The API is obviously returning an Unicode string to you, and you have accepted it into an ANSI style string. The Unicode version of the API was called, because you are doing an Unicode build. To solve this, you could do an MBCS build.
However, I strongly recommend the usage of TCHAR instead of char and use neutral string manipulation functions and APIs - for example, _tcscpy instead of strcpy. _tcscpy will behave like strcpy when you do an MBCS build and will behave like wcscpy when you do an Unicode build. This way, you could do an Unicode build and an MBCS build without making changes in the source code.
Take a look at the "Windows Data types" section of this article[^].
I would also recommend this two part article to you:
The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^]
The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
|
Hi,
- I am trying to execute a GUI dll from my program (.exe)
- I have do all about exporting function that will be called from outside like this
In Dll :
extern "C" __declspec(dllexport) void ExecuteDll(bool A_bDecryptCcs);
What i need is to make a program (.exe) to execute this dll and it will be invisible because i need it to be like a Trigger just call and leave and let the dll working i.e the GUI of the dll still for me.
I hope that i explained my problem clearly and i hope so that someone have a solution and help me.
Thank you
|
|
|
|
|
And what is your problem?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
- It is the DLL which should do all work
- the EXE should call the DLL which is a graphic interface
- the EXE call an exported function from the DLL only
- when i exit from the DLL all work is finished.
i hope that i explained more my situation.
|
|
|
|
|
And what stops you from implementing this? You don't know how to load a DLL, or you don't know how to call the exported method? As far as i can tell from what you said here, all your exe should do is load the DLL, call the exported method which i assume will create a window and run a message loop and after this method finishes, exit. Right?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I recapitulate all problem with:
i will have two files :
- EXE : just lunch the DLL and disappear
- DLL : called with its exported function (it is done) and it has the style of window and will do all work
and when i quit this window(exit from DD) is weening that my all application exit
the problem is when i lunch the EXE file, my window(the DLL) appears and disappears quickly and i need it to stay until i exit from it when i like!
So how can i do this ?
can i use a console application which lunch the DLL and still waiting? or there is an other solution
|
|
|
|
|
When your exe runs, what does it do, show some code (relevand code only). Also, what does your DLL do (also show some relevant code).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
The EXE is just to lunch the DLL , that is all
The dll is a MFC SDI application contains a main window that do all work.
And to lunch this DLL i need this EXE.
So if there is a solution to this situation please help.
|
|
|
|
|
Ok, i understand that, but without knowing some details about what you tried to do i can only guess...
So what i would first try is to simple load the DLL ( LoadLibrary ), and have an exported method -as i mentioned earlier- that brings up the windows and runs the message loop, localize this method (GetProcAddress), call it and let it run until it is done (the user dismisses the window, selects Exit from its menu, whatever...), and then exit. The EXE would sit in memory while the DLL's function is executed but i personally wouldn't care much. For the EXE i'd probably create a DIALOG BASED app in VS, remove the dialog and everything else that gets generated automatically by the app wizard, and in the applications's InitInstance i'd do the loading and executing and then return FALSE from it to exit. Or you could create a barebone project and do about the same just without any app class and the rest...it's up to you.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
It's a simple problem. He wants to launch an application (exe). The application then calls a function in a dll (e.g. ShowMyWindow()) and immediately terminates. But he wants the dll function to continue to run.
Absolutely impossible, and totally stupid.
|
|
|
|
|
I read your posts but i am not absolutely convinced that he wants the exe to literally terminate, he just doesn't want to see it is there, not sure but i think he doesn't mean by that that the exe shouldn't be listed in task manager for example, he just doesn't want to see it on his desktop. But of course i might be wrong, if he really wants the exe to terminate that is indeed problematic...he could try to inject the dll into -i don't know- explorer.exe, start a thread and let it run there, but there has to be a better solution...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Code-o-mat wrote: I read your posts but i am not absolutely convinced that he wants the exe to literally terminate
I agree the description is not overly clear.
Code-o-mat wrote: but there has to be a better solution...
Yes, he could study windows programming and learn what a dll is for.
|
|
|
|