Before writingProgramWhen the COM component is used, it is very likely that Unicode strings and cstring are converted to each other.CodeEasy to use.
- Unless you can confirm the type of the string to be converted, you should first use istextunicode for determination.
For example:
If (istextunicode (pdata, ldatasize, null ))
// Isuincode
Else
// Is not Unicode
- Unicode conversion to string
Char * pbuffer = NULL;
Long lbuffersize;
Lbuffersize = widechartomultibyte (cp_acp, wc_no_best_fit_chars, (lpcwstr) bstrstring,-1, null, 0, null, null );
Pbuffer = new char [lbuffersize + 1];
Widechartomultibyte (cp_acp, wc_no_best_fit_chars, (lpcwstr) (bstrstring),-1, pbuffer, lbuffersize + 1, null, null );
// Use pbuffer...
Delete [] pbuffer;
- Convert string to Unicode
Int nlen = 0;
Wchar_t * punicode = NULL;
Cstring SINFO;
Nlen = multibytetowidechar (cp_acp, 0, SINFO,-1, null, 0 );
Punicode = new wchar_t [nlen + 1];
Multibytetowidechar (cp_acp, 0, SINFO,-1, punicode, nlen );
Several macros are available for ease of use.
Cstringw unicode1 = l "/x0391 and/x03a9"; // 'alpha' and 'omega'
Cstringa utf8 = cw2a (unicode1, cp_utf8 );
Const cstringw unicode2 = ca2w (utf8, cp_utf8 );