How to convert char* to WCHAR* in C

S

sweety

Dear all,

Kindy help to convert the char* ( LPCSTR) to WCHAR*(LPCWSTR). Would be
great if you tell if any function does this job in VC++.

Quick response will be greatfull...as its blocked...

Thanks,
Sweety
 
S

Simon

Hi Sweety,

You can try MultiByteToWideChar.

The MultiByteToWideChar function maps a character string to a
wide-character (Unicode) string. The character string mapped by this
function is not necessarily from a multibyte character set.

int MultiByteToWideChar(
UINT CodePage, // code page
DWORD dwFlags, // character-type options
LPCSTR lpMultiByteStr, // string to map
int cbMultiByte, // number of bytes in string
LPWSTR lpWideCharStr, // wide-character buffer
int cchWideChar // size of buffer
);

For more information, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_17si.asp

Hope this helps.
Regards.
Harry
 
D

David Resnick

sweety said:
Dear all,

Kindy help to convert the char* ( LPCSTR) to WCHAR*(LPCWSTR). Would be
great if you tell if any function does this job in VC++.

Try looking up the standard function "mbtowc".

That MAY do what you want. It depends on what is in the char*. If it
ASCII or
UTF-8, that is fine. If not (e.g. it is the common iso-8859-1 8 bit
encoding
(rather like the old Windows "code page" 1252), you need to convert it
to utf-8 first.
I think there is no standard way to do that, but there are lots of
libraries
around (<OT>example: expat is pretty portable I think</OT>).

-David
 
M

Mark McIntyre

Dear all,

Kindy help to convert the char* ( LPCSTR) to WCHAR*(LPCWSTR). Would be
great if you tell if any function does this job in VC++.

This isn't a C question, since both the types you refer to are part of
Microsoft's language extensions. I'd suggest you search the MSDN
online for wide char to char conversions
Mark McIntyre
 
J

Jordan Abel

Try looking up the standard function "mbtowc".

That MAY do what you want. It depends on what is in the char*. If it
ASCII or UTF-8, that is fine. If not (e.g. it is the common
iso-8859-1 8 bit encoding (rather like the old Windows "code page"
1252), you need to convert it to utf-8 first.

That is not at all clear. There is no requirement that the "multibyte"
representation actually contains any multibyte characters, and even if
so, a system could well use something like Shift-JIS or ISO-2022 for the
multibyte encoding.

(Forgetting for the moment the fact that the system is not required to
use ASCII for the representation of the basic execution character set,
though the characters in this set are, of course, required to be
represented by single bytes)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top