//发送文本信息 public static void sendTextMsg(string wxid, string content) { var msg = new ImportFromDLL.MessageStruct(); msg.wxid = wxid; msg.content = content; sendToWeChatHelper(msg, WM_SendTextMessage); }
//发送底层函数 private static void sendToWeChatHelper(ImportFromDLL.MessageStruct msg, int msgtype) { int cbSize = Marshal.SizeOf(msg); IntPtr StructPtr = Marshal.AllocHGlobal(cbSize); Marshal.StructureToPtr(msg, StructPtr, true); var c = new ImportFromDLL.COPYDATASTRUCT(); c.dwData = msgtype; c.cbData = cbSize; c.lpData = StructPtr; IntPtr wechatWindowHandler = ImportFromDLL.FindWindow(helperWindows, null); var t = ImportFromDLL.SendMessage(wechatWindowHandler, ImportFromDLL.WM_COPYDATA, (IntPtr)5, ref c); Marshal.FreeHGlobal(StructPtr); }