CString has constructors for both char and wchar_t, so you can use either of them.
As for wcscpy_s, I never understands how it works and always crashes for me, even a simple example. Use wcscpy, this always works as expected (no, the problem is NOT in the line when you allocate memory).
Could you post the relevant part of your class declaration for CString, wcscpy_s shouldn't ever get that upset!
BTW - codewalker did get you to correct CString toto((wchar_t*)"test"); to something more suitable.
But I just wanted to check that you picked up why it's so evil to lie to the compiler, that a multi-byte (or Ansi) string is actually Unicode. The terminator for a Unicode string is two 0 bytes, whereas a multi-byte string ends with just a single one (not enough for Unicode). On top of that, if it did display, it is likely to be some wierd characters from some random code page, rather than normal letters.
Using wcsncpy(_text, text, len + 1); solved the problem.
Using CString toto((wchar_t*)"test"); was effectively not a correct manner to write things. It doesn't crash but I get unexpected caracters in some situations.
Using CString toto( _T("test") ); solve this problem.
@Andywestken : I even tried to write a \0\0 at the end of the string, but it didnt help... :)
Anyway, as you pointed, it's not a correct way to write things.
I'm not sure what you call the relevant part of the class CString, so... I give it all. Anyway, so short...
I saw the "Buffer is too small" in debug, but I couldn't get rid of it.
I tried to allocate a buffer with 1000 wchar_t, then copy "len" length. Still same problem.
So... I still can't make the wcscpy_s works, and since the wcsncpy works fine(that means : works as expected, where wcscpy_s doesn't !) I really don't want to know what's going on behind.
If you're interrested, I can send you the whole VS project.