C #: how to convert a C # string to C ++ wstring and vice versa

C # code-

string s = "お は よ う";

I want to send s to a C ++ dll, like wstring ..
how to convert a string to wstring in C #?

+3
source share
1 answer

A std::wstringis a C ++ object allocated by the C ++ runtime and has an internal implementation-dependent format. You may be able to figure out how to create one of them in a C # program and pass it to unmanaged C ++ code, but it will be somewhat difficult and fraught with danger. Since the internal structure std::wstringis implementation dependent, any change in the C ++ compiler or runtime libraries interrupts your decision.

, , ++, LPTStr, std::wstring, ++, . , , , :

int Foo(std::wstring p);

:

int FooCaller(LPTSTR p)
{
    std::wstring str = p;
    return Foo(str);
}

FooCaller #.

, # std::wstring, .

+4

All Articles