[Win32utils-devel] Wide strings and LPCTSTR types
win32utils-devel at rubyforge.org
win32utils-devel at rubyforge.org
Thu Feb 26 09:06:46 EST 2004
Hi,
>
> All,
>
> I was experimenting with converting LPCTSTR strings to wide strings with
> something like this:
>
> // Converts a Ruby string to a LPWSTR
> LPCTSTR AllocWideLString(VALUE rbString){
> char* str = STR2CSTR(rbString);
> int length = (strlen(str)+1) * sizeof(WCHAR);
> LPCTSTR lpStr = (LPCTSTR)malloc(length);
>
> MultiByteToWideChar(
> CP_ACP,
> 0,
> str,
> strlen(str)+1,
> (LPWSTR)lpStr,
> length
> );
>
> return lpStr;
> }
>
> But, that didn't seem to work very well in testing. Is there a better
> way? Otherwise, I'll have to stick to casting for now.
>
> Also, I noticed that there's a IsTextUnicode() function. Should I be
> employing that somehow?
Do You still have trouble with MultiByteToWideChar?
Maybe MultiByteToWideChar hates you :)
Would you try mbstowcs like following?
nLen = strlen(szText) + 1;
wszBuffer = malloc(nLen) * sizeof(WCHAR);
mbstowcs(wszBuffer, szText, nLen);
Regards,
Park Heesob
--MIME Multi-part separator--
More information about the win32utils-devel
mailing list