Home All Groups Group Topic Archive Search About

Returning a string* as a result in WndProc

Author
25 Mar 2005 3:35 PM
Kurt
I 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

Author
25 Mar 2005 4:26 PM
Mattias Sjögren
>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.
Author
25 Mar 2005 5:27 PM
Kurt
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.
>
Author
29 Mar 2005 10:03 AM
Mattias Sjögren
>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.
Author
29 Mar 2005 1:19 PM
Kurt
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.
>

AddThis Social Bookmark Button