theblip
asked on
converting unicode LPTSTR to WCHAR[]
When I step through the code below, I put a watch on szFile and it shows it as containing "c:\files\李克 勤 - 飛花.mpg" (chinese characters in unicode).
I need to convert that to WCHAR[]. so I do a:
wcsncpy(wFile, T2W(szFile,CP_UTF), NUMELMS(wFile)-1);
However, wFile now contains: "c:\files\§õ§J¶Ô - ¸ªá.mpg"
The next bit of code tries to open the file specified by wFile but doesn't succeed because "c:\files\§õ§J¶Ô - ¸ªá.mpg" does not exist. The file that should be opened is "c:\files\李克 勤 - 飛花.mpg". I would like the filename to stay as unicode instead of being converted according to the codepage. What am I doing wrong? Is there something I don't understand?
----------
HRESULT PlayMovieInWindow(LPTSTR szFile)
{
USES_CONVERSION;
WCHAR wFile[MAX_PATH];
HRESULT hr;
if (!szFile)
return E_POINTER;
// Clear open dialog remnants before calling RenderFile()
UpdateWindow(ghApp);
// Convert filename to wide character string
wcsncpy(wFile, T2W(szFile), NUMELMS(wFile)-1);
-------
Edit:: Sorry the unicode I typed did not come out properly...
szFile should contain the chinese unicode...
wFile ends up being converted to multibyte.. so looks like gibberish... but I would like it to be unicode.. because the filename of the file on the drive is in unicode.
I need to convert that to WCHAR[]. so I do a:
wcsncpy(wFile, T2W(szFile,CP_UTF), NUMELMS(wFile)-1);
However, wFile now contains: "c:\files\§õ§J¶Ô - ¸ªá.mpg"
The next bit of code tries to open the file specified by wFile but doesn't succeed because "c:\files\§õ§J¶Ô - ¸ªá.mpg" does not exist. The file that should be opened is "c:\files\李克
----------
HRESULT PlayMovieInWindow(LPTSTR szFile)
{
USES_CONVERSION;
WCHAR wFile[MAX_PATH];
HRESULT hr;
if (!szFile)
return E_POINTER;
// Clear open dialog remnants before calling RenderFile()
UpdateWindow(ghApp);
// Convert filename to wide character string
wcsncpy(wFile, T2W(szFile), NUMELMS(wFile)-1);
-------
Edit:: Sorry the unicode I typed did not come out properly...
szFile should contain the chinese unicode...
wFile ends up being converted to multibyte.. so looks like gibberish... but I would like it to be unicode.. because the filename of the file on the drive is in unicode.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works now without conversion.
I had to do both a
#define UNICODE
and
#define _UNICODE
hmm.. do both need to be defined or just _UNICODE? it doesn't seem to work with just one.
I need to have both #define UNICODE and #define _UNICODE or I get type errors.
But yea.. it works now if I have both defined.