pb 程序之间的消息传递
一、发送消息long ll_handle,ll_rtn
string ls_msg,ls_lenBlob lblob_sndll_handle = long(profilestring(guo_sys.is_inifile,'Set','handle','0'))//主程序窗口,可以通过FindWindowA取得
if ll_handle <> 0 then
ls_msg = '消息'
//计算整个要发送字符的长度,并转化为长度为10的字符串
ls_len = String(Len(ls_msg))
IF Len(ls_len) < 10 THEN
ls_len = Space(10 - Len(ls_len))+ls_len
END IF lblob_snd = Blob(ls_len + ls_msg)
SndMsg(ll_handle,1024,getcurrentprocessID(),lblob_snd)//发送pbm_custom01消息给主程序
end if二、主程序接收消息(窗口的pbm_custom01事件)//wparam发送的进程ID//lparam 发送的进程里的消息地址Long ll_null,ll_processhnd,ll_size
String ls_size,ls_data
blob lb_dataIf (wparam = 0) Or (lparam = 0) THEN RETURNSetNull(ll_null)
ll_processhnd = openprocess(PROCESS_VM_READ,0,wparam);
//读取发送进程的内存数据ls_size = Space(10) //数据的大小
ReadProcessMemoryStr(ll_processhnd,lparam,ls_size,10,ll_null)
ll_size = Long(Trim(ls_size))lb_data = Blob(String(Space(ll_size)))//读取消息内容
ReadProcessMemoryBlob(ll_processhnd,lparam+10,lb_data,ll_size,ll_null)ls_data = String(lb_data)//接收到的消息
CloseHandle(ll_processhnd)三、相关API//接收相关Function ulong OpenProcess(ulong dwDesiredAccess,ulong bInheritHandle,ulong dwProcessId) LIBRARY "kernel32.dll"
Function ulong CloseHandle(ulonghObject) LIBRARY "kernel32.dll"
Function ulong ReadProcessMemoryStr(ulong hProcess,long lpBaseAddress,ref string lpBuffer,ulong nSize,ref long lpNumberOfBytesWritten) LIBRARY "kernel32.dll" Alias for "ReadProcessMemory"
Function ulong ReadProcessMemoryBlob(ulong hProcess,long lpBaseAddress,ref blob lpBuffer,ulong nSize,ref long lpNumberOfBytesWritten) LIBRARY "kernel32.dll" Alias for "ReadProcessMemory"
//发送相关Function ulong GetCurrentProcessId() LIBRARY "kernel32.dll"
Function integer SndMsg(long hWnd, long uMsg, long url,ref blob info) library "user32.dll" Alias For "SendMessageA"
学习了、。。。 收藏了,谢谢
页:
[1]