S
Sean
I am trying to send a WM_COPYDATA message to another application in C#,
..NET 2.0.
The other application receives the message, but only seems to see the
first character of the string, does anybody have any ideas?
I have copied the code below.
class WIN32 {
//SendMessage
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(System.IntPtr hwnd, int
msg, int wparam, int lparam);
//Copy Data Structure
public struct COPYDATASTRUCT
{
public int dwData;
public int cbData;
public int lpData;
}
public static int VarPtr(object e)
{
System.Runtime.InteropServices.GCHandle GC =
System.Runtime.InteropServices.GCHandle.Alloc(e,
System.Runtime.InteropServices.GCHandleType.Pinned);
int gc = GC.AddrOfPinnedObject().ToInt32();
GC.Free();
return gc;
}
}
public class SendTheMessage {
public SendTheMessage(string str, System.IntPtr handle,
System.IntPtr iHandle, System.UInt32 signature) {
Win32.COPYDATASTRUCT cds;
cds.dwData = Convert.ToInt32(signature);
str = str + '\0';
cds.cbData = 3;
cds.lpData = Win32.VarPtr(str);
Win32.SendMessage(handle, Win32.WM_COPYDATA,
0, Win32.VarPtr(cds));
}
}
..NET 2.0.
The other application receives the message, but only seems to see the
first character of the string, does anybody have any ideas?
I have copied the code below.
class WIN32 {
//SendMessage
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(System.IntPtr hwnd, int
msg, int wparam, int lparam);
//Copy Data Structure
public struct COPYDATASTRUCT
{
public int dwData;
public int cbData;
public int lpData;
}
public static int VarPtr(object e)
{
System.Runtime.InteropServices.GCHandle GC =
System.Runtime.InteropServices.GCHandle.Alloc(e,
System.Runtime.InteropServices.GCHandleType.Pinned);
int gc = GC.AddrOfPinnedObject().ToInt32();
GC.Free();
return gc;
}
}
public class SendTheMessage {
public SendTheMessage(string str, System.IntPtr handle,
System.IntPtr iHandle, System.UInt32 signature) {
Win32.COPYDATASTRUCT cds;
cds.dwData = Convert.ToInt32(signature);
str = str + '\0';
cds.cbData = 3;
cds.lpData = Win32.VarPtr(str);
Win32.SendMessage(handle, Win32.WM_COPYDATA,
0, Win32.VarPtr(cds));
}
}