Imports System.Runtime.InteropServices

Public Class Monitor

    <DllImport("user32.dll", CharSet:=CharSet.Unicode, entrypoint:="SendMessageW")> _
Private Shared Function SendMessage(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As Integer) As Integer
End Function Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32 '发送方的代码
Public Shared Sub SendMsg(ByVal message As String)
Dim hWnd As Integer
hWnd = FindWindow(vbNullString, "短信发送服务器")
If hWnd Then ' 有这个窗口
Dim ptr As IntPtr = Marshal.StringToHGlobalUni(message)
SendMessage(hWnd, &H1397, ptr, 0) ' 给类名为SmsServerMonitor的窗口发消息,消息标示为&H1397
Marshal.FreeHGlobal(ptr)
Else
Log.Write("未能找到窗口")
End If
End Sub End Class
Dim flag As Char = Chr(2) ' 正文开始

Dim msg As String = "100,1,15870727024," & Now.ToString & ",1," & flag & "success"

SendMsg(msg) ' ID为1的数据发送成功
' 接收SmsService发过来的消息消息标示为&H1397
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H1397 Then
Dim msg As String = System.Runtime.InteropServices.Marshal.PtrToStringUni(m.WParam) ' 消息格式:
'id,发送状态,手机号码,时间,优先级,内容 Dim flag As Char = Chr(2) ' 正文开始 Dim body() As String = msg.Split(flag) Dim header() As String = body(0).Split(",")
Dim Id As String = header(0)
Dim Status As String = header(1)
Dim Phone As String = header(2)
Dim SendTime As String = header(3)
Dim Priority As String = header(4)
Dim Content As String = body(1) Dim idxRow As Integer = dgvSmsLog.Rows.Add()
dgvSmsLog.Rows(idxRow).Cells(0).Value = Id
dgvSmsLog.Rows(idxRow).Cells(1).Value = Status
dgvSmsLog.Rows(idxRow).Cells(2).Value = Phone
dgvSmsLog.Rows(idxRow).Cells(3).Value = SendTime
dgvSmsLog.Rows(idxRow).Cells(4).Value = Priority
dgvSmsLog.Rows(idxRow).Cells(5).Value = Content Else
MyBase.WndProc(m)
End If
End Sub

使用SendMessage进行进程间通信的更多相关文章

  1. MFC sendmessage实现进程间通信

    用sendmessage实现进程间通信. 1.WM_COPYDATA实现进程间通信 实现方式是发送WM_COPYDATA消息. 发送程序: LRESULT copyDataResult; //copy ...

  2. C#使用SendMessage实现进程间通信的方法

    本文实例讲述了C#使用SendMessage实现进程间通信的方法.分享给大家供大家参考.具体分析如下: 为了深入理解消息机制,先来做一个测试项目 在新建项目的Form1的代码中,加入方法: ? 1 2 ...

  3. C#进程间通信--API传递参数(SendMessage)

    原文 C#进程间通信--API传递参数(SendMessage)  我们不仅可以传递系统已经定义好的消息,还可以传递自定义的消息(只需要发送消息端和接收消息端对自定义的消息值统一即可).下面的发送和接 ...

  4. 进程间通信,把字符串指针作为参数通过SendMessage传递给另一个进程,不起作用

    参数发送进程: CString csCmd=AfxGetApp()->m_lpCmdLine; if (!csCmd.IsEmpty()) { pWndPrev->SendMessage( ...

  5. VC进程间通信之消息传递PostMessge()或SendMessage()

    1.  进程内消息: (1). 仅仅传消息码 (2). 传送消息串 发送端: void CTestDlg::OnBnClickedButtonSend() { CString* msg = new C ...

  6. WM_COPYDATA实现的不同进程间通信

    进程间通信,通过SendMessage向另一进程发送WM_COPYDATA消息,实现不同进程间的消息通信. 需求:已写好一个工具软件,想在不更改当前的软件开发的前提下,实现为后面新开发的软件提供数据推 ...

  7. WM_COPYDATA进程间通信方案

    连续在两个公司使用WM_COPYDATA实现进程间通信了,整理一下 具体步骤: 一.   进程A通过ShellExecute启动进程B, 将用于通信的窗口句柄hWndA(已强转为int值)通过命令行参 ...

  8. CE 进程间通信

    WINCE下进程间通信常用的方式有:剪贴板(Clipboard),网络套接字(Socket),WM_COPYDATA消息,共享内存,管道(消息队列),注册表等 剪贴板 //////////////// ...

  9. [转]Windows进程间通信的各种方法

    http://www.cnblogs.com/songQQ/archive/2009/06/03/1495764.html 道相似,不过它传输数据是通过不可靠的数据报(如TCP/IP协议中的UDP包) ...

随机推荐

  1. dbt- 数据构建工具

    dbt(数据构建工具)是一个命令行工具,只需编写select语句即可转换仓库中的数据. dbt处理将这些select语句转换为表和视图.DBT帮助做T的ELT(提取,加载和转换) 的过程-它不提取或加 ...

  2. 使用EntityFramework6连接MySQL

    使用EntityFramework6连接MySQL 不是微软的亲儿子这待遇就是不一样,其中的坑可真实不少,第一次连MySQL足足折腾了我大半天. 废话不多说直接开始. 安装MySQL 从官网上下载最新 ...

  3. 充电 IC 对 0V 电池充电问题

    只讨论锂聚合物电池,由于设置漏电流原因,有些锂电池会放电到 0V(正常是不应该的). 但是在时候就是会发电到 0V,这里就要考虑充电 IC 是否有对 0V 电池充电的功能,还有保护 IC 是否允许 0 ...

  4. 【转】每天一个linux命令(6):rmdir 命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/10/27/2742076.html 今天学习一下linux中命令: rmdir命令.rmdir是常用的命 ...

  5. 修改Nginx的header伪装服务器

    有时候为了伪装自己的真实服务器环境.不像让对方知道自己的webserver真实环境,就不得不修改我们的webserer软件了!今天看了一下baidu.com的webserver感觉像是nginx修改的 ...

  6. import和export语法报错

    “最近在学习ES6”,但是在chrome中新建了js通过ES6语法(import,export)无法引入外部JS,报错: Uncaught SyntaxError:Unexpected token { ...

  7. Microsoft Dynamics CRM 2013 安装 报表服务出现“ SQL Server Reporting Services 帐户是本地用户且不受支持 ”错误的解决方法

    安装好CRM 2013 之后,还需要安装报表服务,发现出现:SQL Server Reporting Services 帐户是本地用户且不受支持,具体如下图: 经过分析原来发现是需要用域用户,打开对应 ...

  8. hello world之Makefile

    hello world之Makefile

  9. jquery tmpl学习资料 --{{each}} each使用

    <!DOCTYPE html><html><head>    <script src="Scripts/jquery-1.6.2.min.js&qu ...

  10. Python 中的变量

    Python采用基于值得内存管理模式,赋值语句的执行过程是:首先把等号右侧标识的表达式计算出来,然后在内存中找一个位置把值存放进去,最后创建变量并指向这个内存地址.Python中的变量并不直接存储值, ...