|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Returning a string* as a result in WndProcI have a C++ dialog that is sending a message to my C# window and I need to
pass a string* back in the result of the message. On the C++ side this result is cast as a CString*. How do I create this string on the C# side and convert it to an IntPtr? My first guess is to allocate memory and copy the string to it and then let the C++ app clean it up. Thanks Kurt >How do I create this string on the C# side and convert Sure that will work, and you can do it with one of the>it to an IntPtr? My first guess is to allocate memory and copy the string to >it and then let the C++ app clean it up. Marshal.StringTo* methods. Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Ok I'm using StringToHGlobalAnsi and the string I get on the other side is
blank. Here is my code on the C++ side. CString p((char*)lResult); Show quote "Mattias Sjögren" wrote: > >How do I create this string on the C# side and convert > >it to an IntPtr? My first guess is to allocate memory and copy the string to > >it and then let the C++ app clean it up. > > Sure that will work, and you can do it with one of the > Marshal.StringTo* methods. > > > > > Mattias > > -- > Mattias Sjögren [MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. > >Ok I'm using StringToHGlobalAnsi and the string I get on the other side is You're gonna have to show more of your code. >blank. > >Here is my code on the C++ side. > >CString p((char*)lResult); Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Thanks Mattias I figured it out.
Show quote "Mattias Sjögren" wrote: > > >Ok I'm using StringToHGlobalAnsi and the string I get on the other side is > >blank. > > > >Here is my code on the C++ side. > > > >CString p((char*)lResult); > > > You're gonna have to show more of your code. > > > > Mattias > > -- > Mattias Sjögren [MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. > |
|||||||||||||||||||||||