Convert OLECHAR * to CHAR * to create string ()

I have an OLECHAR * and I want to convert it to CHAR * to create a string from it, I haven't found a way to do this.

Is OLECHAR a regular char? did not think about it.

Thanks in advance, Gal.

+3


source to share


2 answers


OLECHAR

- character string wchar_t

. I recommend reading The Complete Guide to C ++ Strings Part II - String Wrapping Classes .



+4


source


OLECHAR*

- Unicode string (UTF-16) wchar_t

. If you want to convert it to a string CHAR*

, you should clarify what specific encoding you are going to use for the conversion.

For example, you can convert from UTF-16 to UTF-8 (this is a lossless conversion), and you can store the UTF-8 string in CHAR*

/ std::string

(I prefer to use reliable string classes instead of raw pointers in C ++ code).



To do the conversion, you can use the WideCharToMultiByte()

Win32 API. You can use the value CP_UTF8

"codepage" if you want to convert from UTF-16 to UTF-8. For "ANSI" (potentially lossy) conversion you can use CP_ACP

etc.

(There are also handy ATL wrappers for the aforementioned Win32 API, for example CW2A

, but I'm not sure what level of functionality is available in the VC6 version of those wrappers.)

+1


source







All Articles