>.... Now, in a member function, I need to call a native
>function that takes a std::wstring parameter. Of course, the compiler
>is complaining of me trying to convert String^ to std::wstring.
>
>What is the solution?
I use a function like this:
static void SystemStringToStdString(String ^ SystemString, wstring &
StdString)
{
IntPtr ip = Marshal::StringToHGlobalUni( SystemString );
const wchar_t * ps = static_cast<const wchar_t
*>(ip.ToPointer());
StdString = ps;
Marshal::FreeHGlobal( ip );
}
There are some built-in conversions facilities in VS2008 but when I
tried them they were less efficient that the above method.
Dave
Jochen Kalmbach [MVP] - 19 Sep 2007 17:30 GMT
Hello David!
>> .... Now, in a member function, I need to call a native
>> function that takes a std::wstring parameter. Of course, the compiler
>> is complaining of me trying to convert String^ to std::wstring.
> static void SystemStringToStdString(String ^ SystemString, wstring &
> StdString)
[quoted text clipped - 5 lines]
> Marshal::FreeHGlobal( ip );
> }
This solution is "overkill"...
Please use simply "PtrToStringChars"... this is the fastest method...

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
David Lowndes - 19 Sep 2007 18:28 GMT
>This solution is "overkill"...
>
>Please use simply "PtrToStringChars"... this is the fastest method...
True - and I knew it too having posed the same question elsewhere. I'm
getting a short memory these days :(
Dave