WIN32汇编的接受程序收到的小心总是0
求解啊?接收到的消息总是0.以下是send程序
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
hWnd dd ?
szBuffer db 256 dup(?)
stCopydata COPYDATASTRUCT <>
.const
szClassName db 'MyClass',0
szStart db 'Press OK to send message %08x!',0
szTextdb 'THIS IS THE MEESSAGE I SEND JUST NOW!',0
szCaption db 'sending ...',0
szReturn db 'I have return from the hell!',0
szError db 'opps!',0
.code
start:
invoke FindWindow,offset szClassName,NULL
.if eax
mov hWnd ,eax ;取得目标窗口的句柄
invoke wsprintf,offset szBuffer,offset szStart,offset szText
invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK
invoke SendMessage,hWnd,WM_COPYDATA,0,offset stCopydata
mov stCopydata.cbData,sizeof szText
mov stCopydata.lpData,offset szText
mov stCopydata.dwData,offset szText
invoke MessageBox,NULL,offset szReturn,offset szCaption,MB_OK
.else
invoke MessageBox,NULL,offset szError,offset szCaption,MB_OK
.endif
invoke ExitProcess,NULL
end start
本帖最后由 メ㊣逆ご帅☆ 于 2012-8-27 20:03 编辑
其他程序我没看,我只看发送程序
invoke SendMessage,hWnd,WM_COPYDATA,0,offset stCopydata
mov stCopydata.cbData,sizeof szText
mov stCopydata.lpData,offset szText
mov stCopydata.dwData,offset szText
你顺序搞错了吧。_ _
应该先赋值后发送
不行再叫我
mov stCopydata.cbData,sizeof szText
mov stCopydata.lpData,offset szText
mov stCopydata.dwData,offset szText
invoke SendMessage,hWnd,WM_COPYDATA,0,offset stCopydata
另外遇到问题最好直抓重点
发送的值为0?谁发送的?发送的那个步骤没错?没错,OK,向上找,看发送的数据来源
以下是接收程序:
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Sample code for < Win32ASM Programming 3rd Edition>
; by 罗云彬, http://www.win32asm.com.cn
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; SendMessage.asm
; 从一个程序向另一个窗口程序发送消息 之 发送程序
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 使用 nmake 或下列命令进行编译和链接:
; ml /c /coff SendMessage.asm
; Link /subsystem:windows SendMessage.obj
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
hWnd dd ?
szBuffer db 512 dup (?)
stCopyData COPYDATASTRUCT <>
szCaption db 'SendMessage',0
szStart db 'Press OK to start SendMessage, text address: %08x!',0
szReturn db 'SendMessage returned!',0
szDestClass db 'MyClass',0 ;目标窗口的窗口类
szText db 'Text send to other windows',0
szNotFound db 'Receive Message Window not found!',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
start:
invoke FindWindow,addr szDestClass,NULL
.if eax
mov hWnd,eax ;找到目标窗口则发送消息
invoke wsprintf,addr szBuffer,addr szStart,addr szText
invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK
mov stCopyData.cbData,sizeof szText
mov stCopyData.lpData,offset szText
invoke SendMessage,hWnd,WM_COPYDATA,0,addr stCopyData
invoke MessageBox,NULL,offset szReturn,offset szCaption,MB_OK
.else
invoke MessageBox,NULL,offset szNotFound,offset szCaption,MB_OK
.endif
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
错了。。。。1L是发送程序,3L是接收程序
以下:
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include user32.inc
include kernel32.inc
include windows.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
include gdi32.inc
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMaindd ?
szBuffer db 100 dup(?)
.const
szClassName db 'MyClass',0
szCaptiondb 'My first window',0
szText db 'shit this is bull shit!',0
szReceiveMessage db 'This is the message I received:',0dh,0ah
db 'Param :%x08',0dh,0ah
db 'text:%s',0dh,0ah,0
szReceiveMessage2 db 'This is the message:',0dh,0ah
db 'lengthof data: %d',0dh,0ah
db 'text :"%s"',0dh,0ah
db 'value address:%08x',0dh,0ah,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>窗口过程
.code
_ProcWinmain proc uses ebx esi edi hWnd,uMsg,wParam,lParam;需要几个信息参数:uMsg:消息类型,PARAM消息的两个参数
local @stPs:PAINTSTRUCT ;stPs 用于存放创建和关闭窗口的窗口绘制信息
local @stRect:RECT ;stRect用于存放窗口客户区的坐标
local @hDc ;hDc用于存放要输出的窗口设备
mov eax,uMsg
.if eax == WM_PAINT
invoke BeginPaint,hWnd,addr @stPs
mov @hDc,eax
invoke GetClientRect,hWnd,addr @stRect ;用于取得窗口客户区的坐标,将其值放入stRect
invoke DrawText,@hDc,addr szText,-1,addr @stRect,DT_SINGLELINE or\
DT_CENTER or DT_VCENTER
invoke EndPaint,hWnd,addr @stPs
.elseif eax == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.elseif eax == WM_SETTEXT
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK
invoke wsprintf,offset szBuffer,addr szReceiveMessage,lParam,lParam
invoke MessageBox,NULL,offset szBuffer,offset szCaption,MB_OK
.elseif eax == WM_COPYDATA
mov eax,lParam
assume eax:ptr COPYDATASTRUCT
invoke wsprintf,offset szBuffer,offset szReceiveMessage2,\
.cbData,.lpData,.lpData
invoke MessageBox,hWnd,offset szBuffer,offset szCaption,MB_OK
assume eax:nothing
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
_ProcWinmain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
local @stWndClass:WNDCLASSEX
local @stMsg:MSG ;存放消息循环中要用到的消息
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>注册窗口类
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
mov @stWndClass.cbSize,sizeof @stWndClass
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinmain
push hInstance
pop @stWndClass.hInstance
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
invoke LoadIcon,0,IDI_ASTERISK
mov @stWndClass.hIcon,eax
mov @stWndClass.hbrBackground,COLOR_WINDOW+1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>创建窗口
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,offset szClassName,offset szCaption,WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hInstance,NULL
mov hWinMain,eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>显示窗口
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>消息循环
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0 ;取得消息为WM_QUIT的时候返回0值
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>开始
start :
call _WinMain
invoke ExitProcess,NULL
end start
メ㊣逆ご帅☆ 发表于 2012-8-27 20:00 static/image/common/back.gif
其他程序我没看,我只看发送程序
invoke SendMessage,hWnd,WM_COPYDATA,0,offset stCopydata
真屎。。。。。。居然错在这里了。。。码字码的都有点晕了
页:
[1]