#include "stdafx.h"
#include "string.h"
#include "windows.h"
bool SCS_GetAgentInfo(char name[32],char version[32], char description[256], const char * dwAppVersion)
{
strcpy(name,gName);
strcpy(version,gVersion);
strcpy(description,gDescription);
notify(dwAppVersion);
return true;
}
void notify(const char * msg)
{
MessageBox(NULL, TEXT(msg), NULL, NULL);
}
I have managed to work with the first three fields fine, but I am running into issues with the const char *. I have tried passing and casting in alot of different ways, but can’t get it to work. I googled around, but couldn’t find much on Lmsg. I am new to alot of this. I have read around and I think it may have to do with encoding. What really confuses me is LPCTSTR is defined as a const char *, but straight typecasting doesn’t give me anything from the field.
I get an error that Lmsg is undeclared which I am guessing means that the Macro expansion of TEXT is causing this. How can I get this working?
Doing MessageBox(NULL, (LPCTSTR)msg, NULL, NULL); instead gives me a bunch of boxes indicating it probably is referencing the wrong characters, but copying the dwAppsVersion parameter into the description shows the correct information.
The problem is that you’re building you application to use UNICODE Win32 API’s, but you’re passing around non-UNICODE strings. You have two options:
convert the
msgstring to Unicode using something likeMultiByteToWideChar(). This is probably the ‘right’ way to do it, if a bit more complex because you need to deal with codepages and managing the buffers used for the conversion.you can force the ANSI version of the API to be used:
That’s a simple workaround, if not elegant.
Other options include only building the application to use Win32 ANSI APIs instead the Unicode APIs or changing the strings you pass around as
LPTSTRand using theTEXT()or_T()macros for your literals. However, if you’re reading non-Unicode data from files or elseswhere, then you still have to deal with the conversion at some point…