将字符串以消息的模式发送到其他窗口遇到点问题,大家来看下?

zhujiechang 2005-06-27 01:08:38
这个窗口是其他程序的窗口,同样的VB程序。
能正确接收到消息,但却不能正确获得字符串和数字。
但以相同程序发送到自己程序内的窗口却能正确获得字符串和数字。请问通常的处理是怎么解决?
发送端代码:
private const MSG_Error=&H1900
dim ErrStr as string
dim I as long,J as long
ErrStr = "Thello word"
i = VarPtr(ErrStr)
j=41000
SendMessage Me.hwnd, MSG_Error, i, j (如果me.hwnd换成其他程序的窗口HWND则无法正确获得)
接收端代码:
Dim ErrStr2 As String,tempStr As String
Dim tempAddress As Long,tempAddress2 As Long
Dim ErrNumber As Long
If iMsg = MSG_Error Then
tempStr = "大家好!"
tempAddress2 = VarPtr(tempAddress)
Call CopyMemory(tempAddress2, VarPtr(tempStr), 4)
Call CopyMemory(VarPtr(tempStr), wParam, 4)
ErrStr2 = Trim(tempStr)
Call CopyMemory(VarPtr(tempStr), tempAddress2, 4)
Call CopyMemory(ByVal VarPtr(ErrNumber), ByVal lParam, 4)

MsgBox "错误号:" & ErrNumber & Chr(13) _
& "错误描述:" & ErrStr2 & Chr(13) _
& "原字符串:" & tempStr
End If
...全文
115 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zlt982001 2005-07-04
  • 打赏
  • 举报
回复
如果,都是VB 的程序,建议使用 DDE ,实现容易,且稳定
如果不是,可以使用 文件共享内存映射 的方法

以上方法都可以在这里轻易搜索到,我就不贴了
homezj 2005-07-04
  • 打赏
  • 举报
回复
这里包含两个问题:

1、其它程序是否能处理MSG_Error消息;

2、VarPtr函数用于String,取得的是BSTR格式字符串的指针,它实际指向包含自动化String的头部信息的Unicode编码字符串(实际Unicode字符串首字符地址应用StrPtr函数获取),VB是支持的。但大多数C写的Windows程序只支持LPSTR格式字符串,所以对于发送字符串的API调用,一般可用Byte数组,或Byval String声明API来传送;
zhujiechang 2005-07-04
  • 打赏
  • 举报
回复
用其他的方法实现了,用文件共享内存映射的方法来做了。
相关API:
Private Declare Function CreateFileMapping Lib "kernel32" Alias "CreateFileMappingA" (ByVal hFile As Long, lpFileMappigAttributes As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long
Private Declare Function MapViewOfFile Lib "kernel32" (ByVal hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long
zhujiechang 2005-06-28
  • 打赏
  • 举报
回复
自己顶下!

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧