PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

LPSTR to LPWSTR ?

Hello i need some help

I want to convert a char* in an unsigned short* in order to use the GDI fonction DrawText.
In the same way I want to convert a float -> unsigned short*

Someone can help me please ?

Swann
Here, have fun!

Code:
wchar_t *ToWideChar(char s[])
{
wchar_t *w;
w = (wchar_t *)malloc(sizeof(wchar_t)*strlen(s)+1);
MultiByteToWideChar(CP_ACP, 0, s, -1, w, strlen(s));
w[strlen(s)]=0;
return w;
}


Regards,
Kornalius
Or, to do it without writing a function specifically for that, use mbstowcs() and wcstombs(). To convert the float to an unsigned short*, do you mean that you want it to be a string? If so, then you'll be wanting sprintf(). I can;t remeber all of the parameters and exactly how they work, but they are all in the MSDN help. HTH
Well, this doesn't really need to be a separate function either. The w[strlen(s)]=0; is not necessary:

cbMultiByte
If this parameter is -1, the function processes the entire input string including the null terminator. The resulting wide character string therefore has a null terminator, and the returned length includes the null terminator.

If you've got a static buffer you're translating the string into then you can just do a simple call:

TCHAR szOut[1024];
WideCharToMultiByte(CP_ACP, 0, s, -1, szOut, sizeof(szOut)/sizeof(TCHAR));

_stprintf is the TCHAR version of sprintf.

Dan East