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. struts2访问ServletAPI方式和获取参数的方式

    一.访问ServletAPI的三种方式 方式1:通过让Action类去实现感知接口. 此时项目依赖:servlet-api.jar. ServletRequestAware:感知HttpServlet ...

  2. ehci及其伴随ohci主机控制器驱动分析

    1. 正常插入 插上U盘产生中断调用usb_hcd_irq: usb_hcd_irq ehci_irq usb_hcd_resume_root_hub queue_work(pm_wq, &h ...

  3. day37 mysql数据库学习

    3.什么是数据库 用来存储数据的仓库 数据是以文件的形式保存 海峰补充内容   ↓ 4 数据库服务器.数据管理系统.数据库.表与记录的关系(重点理解!!!) 记录:1 刘海龙  324245234 2 ...

  4. ORA-01791: not a SELECTed expression

    Student表有3个字段:id,name,age 看这两个SQL语句 (1)select name from student order by id; (2)select distinct(name ...

  5. MSMQ-发送消息到远程专用队列path格式

    在工作组模式下,远程访问专用队列.在网上找到一篇文章,翻译了一下. 最后结论,直接使用多元素格式名方式,利用IP地址直接对单个或多个目标发送消息      MessageQueue rmQ = new ...

  6. JVM监控

    jconsole 说明: 首先JConsole这个是JDK里面自带的工具  在JAVA_HOME/bin目录下,今天主要测试远程监控JVM 第一步:设置好需要远程机器的Tomcat 修改Tomcat下 ...

  7. RabbitMQ之监控

    RabbitMQ作为一个工业级的消息中间件,肯定是缺少不了监控的,RabbitMQ提供了WEB版的页面监控(访问地址:http://xxx.xxx.xxx.xxx:15672/,默认端口号是15672 ...

  8. 【转】Ubuntu12.04 LTS下环境变量设置

    原文网址:http://blog.chinaunix.net/uid-26963688-id-3221439.html 1.设置当前用户环境变量(对root用户无效) 打开终端输入:light@cha ...

  9. 前端可视化建模技术概览,包括:GoJS

    我推荐使用的: 库 网址 备注 GoJS https://gojs.net/latest/samples/flowchart.html 推荐使用 相关文章: 前端可视化建模技术概览:http://le ...

  10. php 实现欧拉函数Euler

    欧拉函数ph(n)的意思是所有小于n且与n互质的个数.比如说ph(10) = 4{1,3,7,9与10互质} 代码如下: function Euler($x) { $res = $x; $now = ...