How to convert char * to LPCWSTR???
I''m not entirely sure, but what about using TCHAR in place of char* perhaps? I can be entirely wrong, and I apologize if so.
MultiByteToWideChar, probably using CP_ACP. This is during runtime.
If you just want to have a constant string use the L-Makro.
If you just want to have a constant string use the L-Makro.
could you please give me an example of using multibyte thanks, like when i use the same as another one on the net it gets an access violation, i don''t know what to do, ive filled out everything properly
so why would it be getting an access violation and crashing??
thanks,
string song="track3.mp3";LPWSTR mp3File;MultiByteToWideChar(CP_ACP,0,song.cstr(),-1,mp3File,MAX_PATH);
so why would it be getting an access violation and crashing??
thanks,
There are some microsoft macros which make this very easy:
USES_CONVERSION; - put this in to enable the conversions
A2W(lpa) - converts char* to wchar*
W2A(lpw) - the wchar* to char*
here''s all of them (taken from MSDN):
A2CW (LPCSTR) -> (LPCWSTR)
A2W (LPCSTR) -> (LPWSTR)
W2CA (LPCWSTR) -> (LPCSTR)
W2A (LPCWSTR) -> (LPSTR)
these are all contained in AFXPRIV.H - which is MFC I think : (
but also come with ATL. If you don''t want to use either then just find the macro definitions and copy them.
USES_CONVERSION; - put this in to enable the conversions
A2W(lpa) - converts char* to wchar*
W2A(lpw) - the wchar* to char*
here''s all of them (taken from MSDN):
A2CW (LPCSTR) -> (LPCWSTR)
A2W (LPCSTR) -> (LPWSTR)
W2CA (LPCWSTR) -> (LPCSTR)
W2A (LPCWSTR) -> (LPSTR)
these are all contained in AFXPRIV.H - which is MFC I think : (
but also come with ATL. If you don''t want to use either then just find the macro definitions and copy them.
Don''t do
LPWSTR mp3File;
That''s only a pointer to a wide char string. Do a
WCHAR mp3File[260];
You gave MultiByteToWideChar only a pointer to some random address. Upon writing there it would crash of course.
cchWideChar gets the size (number of w-characters) of the target buffer, in the upper case 260.
So make it
LPWSTR mp3File;
That''s only a pointer to a wide char string. Do a
WCHAR mp3File[260];
You gave MultiByteToWideChar only a pointer to some random address. Upon writing there it would crash of course.
cchWideChar gets the size (number of w-characters) of the target buffer, in the upper case 260.
So make it
string song="track3.mp3";WCHAR mp3File[260];MultiByteToWideChar( CP_ACP, 0, song.cstr(), -1, mp3File, 260 );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement