Re: CString to Unicode
pfArt wrote:
I want to convert a ANSI CString to a Unicode CString but none of the
options seems to work...
CString is based on TCHAR, who's meaning varies...
I'm working in VS6 and program is build with _UNICODE.
....so a TCHAR is now a wchar_t.
Here is a example of what i want:
CString test1="test string";
With TCHAR=wchar_t, this already does a conversion char->wchar_t.
CString test2 = L"test string";
This is a simple copy.
CString test3;
Now in test3 I try to store test1 as unicode
Since a conversion took place, test1 already contains wchar_t, which are
Unicode under win32.
so I can execute the next statement:
if (test2.CompareNoCase(test3)==0)
{
//Do something
}
That just works. What's the problem?
I've tried :
* test3 = T2CW(test1);
Should work, assuming you somewhere used the 'USES_CONVERSION' macro.
* BSTR aBuf = NULL;
aBuf = test1.AllocSysString();
SysFreeString(aBuf);
test3 = aBuf;
Nah, too complicated and too much manual resource handling. ;)
* test3=_T(test1) //error
_T() is a macro, which can only be applied to string literals and prefixes
them with nothing or 'L', depending on the _UNICODE macros. test1 is a
string object, so this can't work.
* and many others, but none of them work here
Anyone got a solution?
Peter, if you say something doesn't work, you should be a bit more specific.
If you have time, take a look at Eric S. Raymond's essay on 'asking smart
questions', it contains explanations you could make use of (in fact anybody
could).
Uli