1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| #region SendReceiveMessage
[DllImport("user32.dll")] public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public const int WM_APP = 0x8000; public const int WM_MYMSG =WM_APP + 0x100;
void SendMessageToUnmanaged() { IntPtr hWnd = FindWindow(null, "Fenstername");
string s = "Somestring";
IntPtr sNative = Marshal.StringToHGlobalAuto(s); IntPtr result = SendMessage(hWnd, WM_MYMSG, (IntPtr)1234, sNative); Marshal.FreeHGlobal(sNative);
}
#endregion |