使用SendMessage进行进程间通信
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进行进程间通信的更多相关文章
- MFC sendmessage实现进程间通信
		
用sendmessage实现进程间通信. 1.WM_COPYDATA实现进程间通信 实现方式是发送WM_COPYDATA消息. 发送程序: LRESULT copyDataResult; //copy ...
 - C#使用SendMessage实现进程间通信的方法
		
本文实例讲述了C#使用SendMessage实现进程间通信的方法.分享给大家供大家参考.具体分析如下: 为了深入理解消息机制,先来做一个测试项目 在新建项目的Form1的代码中,加入方法: ? 1 2 ...
 - C#进程间通信--API传递参数(SendMessage)
		
原文 C#进程间通信--API传递参数(SendMessage) 我们不仅可以传递系统已经定义好的消息,还可以传递自定义的消息(只需要发送消息端和接收消息端对自定义的消息值统一即可).下面的发送和接 ...
 - 进程间通信,把字符串指针作为参数通过SendMessage传递给另一个进程,不起作用
		
参数发送进程: CString csCmd=AfxGetApp()->m_lpCmdLine; if (!csCmd.IsEmpty()) { pWndPrev->SendMessage( ...
 - VC进程间通信之消息传递PostMessge()或SendMessage()
		
1. 进程内消息: (1). 仅仅传消息码 (2). 传送消息串 发送端: void CTestDlg::OnBnClickedButtonSend() { CString* msg = new C ...
 - WM_COPYDATA实现的不同进程间通信
		
进程间通信,通过SendMessage向另一进程发送WM_COPYDATA消息,实现不同进程间的消息通信. 需求:已写好一个工具软件,想在不更改当前的软件开发的前提下,实现为后面新开发的软件提供数据推 ...
 - WM_COPYDATA进程间通信方案
		
连续在两个公司使用WM_COPYDATA实现进程间通信了,整理一下 具体步骤: 一. 进程A通过ShellExecute启动进程B, 将用于通信的窗口句柄hWndA(已强转为int值)通过命令行参 ...
 - CE 进程间通信
		
WINCE下进程间通信常用的方式有:剪贴板(Clipboard),网络套接字(Socket),WM_COPYDATA消息,共享内存,管道(消息队列),注册表等 剪贴板 //////////////// ...
 - [转]Windows进程间通信的各种方法
		
http://www.cnblogs.com/songQQ/archive/2009/06/03/1495764.html 道相似,不过它传输数据是通过不可靠的数据报(如TCP/IP协议中的UDP包) ...
 
随机推荐
- USB速率识别
			
低速设备D-上有一个1.5k欧的上拉电阻.高速和全速设别在D+上有一1.5k欧上拉电阻.连接后通过检测电压变化来了解设备是否为低速设别. 低速下:D+为“0”,D-为“1”是为“J”状态,“K”状态相 ...
 - Json.NET Updates: Merge, Dependency Injection, F# and JSONPath Support
			
Json.NET 6.0 received 4 releases this year, the latest last week. Over these releases, several new f ...
 - 变量延迟(setlocal)之浅见
			
变量延迟,浅见认为就是变量预处理,在事先声明变量,告诉cmd环境哪个先哪个后.默认情况下是停用,可以用两种方法启用/停用: 一.cmd /v:on 和cmd /v:off ,范围在cmd这个环境直至e ...
 - Asp.net自定义控件系列(一)
			
最近看到公司某个网站中用到了自定义控件,咋一眼看去,不明白什么玩意, 网上一搜,好像确实不是几句话就能写出强大的自定义控件.好吧,作为一个码农,我决定从基本学起,写一个关于自定义控件学习过程系列. 当 ...
 - Navicat导出opencart2.3数据字典
			
步骤请参考:http://blog.csdn.net/maquealone/article/details/60764420 运行SQL: 备注:opcml是数据库名称. select TABLE ...
 - Dynamics CRM 2011 快速查找 出现异常 QuickFindQueryRecordLimit exceeded. Cannot perform this operation 的解决方法
			
一.CRM 2011 快速查找,输入编号的签名几个字母发现查询很慢. 图 1 当然在图1 上右边的出入框输入编号的部分的时候,有时候会发现数据在加载中..,非常慢,通过Crm Trace Log Vi ...
 - java编码-多重(乱码)
			
一.1,UTF编码 - 2,ISO解码 - 3,UTF编码 - 4,ISO解码 String ISO = "ISO-8859-1"; String UTF = "UTF- ...
 - debian之apt源
			
美国的 deb http://ftp.us.debian.org/debian stable main contrib non-freedeb-src http://ftp.us.debian.org ...
 - view的setTag() 和 getTag()应用 ViewHolder
			
转自 http://www.cnblogs.com/qingblog/archive/2012/07/03/2575140.html View中的setTag(Onbect)表示给View添加一个格外 ...
 - 搭建OpenStack先电云平台
			
实际操作示意图 在VMware里面创建两台centos7的虚拟机作为搭建云平台的两节点配置如下: 1.第一台虚拟机 作为控制节点 2CPU 3G以上内存 硬盘50G 网络适配器一个nat 一个仅主 ...