Here is func :
char *ToLowerSTR(/*char*/ WCHAR* buffer) // NEED TO FIX UNRESOLVED EXTERNAL
{
CHAR* str;
MultiByteToWideChar(CP_ACP, 0, str, strlen(str) + 1开发者_JAVA百科, buffer, sizeof(buffer)/sizeof(WCHAR));
....
return str;
}
and error :
LNK2019: unresolved external symbol "char * __cdecl ToLowerSTR(char *)" (?ToLowerSTR@@YAPADPAD@Z) referenced in function "unsigned long __cdecl GetPID(char *)" )
how can I conver wchar * to char * ?
Your linker is trying to find a function like:
char * ToLowerSTR(char *)
but you have defined your function to take WCHAR
as argument.
Look at the declaration of your function and see if it says WCHAR*
or char*
The error is due to your header file declaring a char * ToLowerSTR(char *)
whereas your cpp file has a different function, char * ToLowerSTR(WCHAR *)
In order to correctly convert, you need to pass the length of the WCHAR buffer to your ToLowerStr
function (Why ToLower btw, what is it supposed to do?). You cannot use sizeof
on the passed WCHAR *
- that'll give you the size of a pointer, not the length of the buffer it points to.
bool charToWChar(char const * Source, wchar_t * Dest, size_t DestLen) {
return MultiByteToWideChar(CP_ACP, 0, Source, -1, Dest, DestLen) != 0;
}
Then call it like this:
char const * myString = "abc";
wchar_t Buffer[100];
charToWChar(myString, Buffer, 100);
What Default said, plus: OMG, you're putting stuff into where str
points, without pointing it in the right direction (like new
or malloc
) first..!
精彩评论