>The other application receives the message, but only seems to see the[color=blue]
>first character of the string, does anybody have any ideas?[/color]
How does the recieving code look like?
[color=blue]
> //SendMessage
> [System.Runtime.InteropServices.DllImport("user32.d ll")]
> public static extern int SendMessage(System.IntPtr hwnd, int
>msg, int wparam, int lparam);[/color]
This is better declared as
[System.Runtime.InteropServices.DllImport("user32.d ll",
CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(System.IntPtr hwnd, int msg,
IntPtr wparam, ref COPYDATASTRUCT lparam);
[color=blue]
> //Copy Data Structure
> public struct COPYDATASTRUCT
> {
> public int dwData;
> public int cbData;
> public int lpData;
> }[/color]
lpData and dwData should be IntPtrs.
[color=blue]
> public static int VarPtr(object e)
> {
> System.Runtime.InteropServices.GCHandle GC =
>System.Runtime.InteropServices.GCHandle.Alloc(e ,
>System.Runtime.InteropServices.GCHandleType.Pinne d);
> int gc = GC.AddrOfPinnedObject().ToInt32();
> GC.Free();
> return gc;
> }[/color]
This is completely broken. If a garbage collection happens after the
GC.Free call, your pointer is invalid. Use one of the
Marshal.StringTo* methods to copy the string to a native buffer
instead, and assign the result to cds.lpData.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
Please reply only to the newsgroup.