如何使用wsadata结构MASM32

时间:2017-11-28 12:07:41

标签: assembly winsock2 masm32

我试图在masm32上建立一个非常简单的客户端(我第一次参加,我之前几乎没有使用过tasm的经验)。 我试图用WSAStartup初始化Winsock dll,我必须给它wsadata stracutre。

我试着这样做,但是我收到了一个错误:

.data
    wsadata WSADATA <>

.code

main:
    invoke WSAStartup, 101H, offset wsadata
    invoke ExitProcess, 0
end main

错误

client.asm(15) : error A2008: syntax error : wsadata 
client.asm(24) : error A2006: undefined symbol : wsadata 
client.asm(24) : error A2114: INVOKE argument type mismatch : argument : 2

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

你可能在wsadata前有一个不可打印的字符

如果您的编辑器显示所有字符选项使用它或

删除该行并从第0列重新输入

addr和offset wsadata都应正确汇编而不会出错

E:\wsadatatest>type wsadatatest.asm
.386
.model flat , stdcall

option casemap:none

include e:\masm32\include\windows.inc
include e:\masm32\include\kernel32.inc
include e:\masm32\include\user32.inc
include e:\masm32\include\ws2_32.inc

includelib e:\masm32\lib\kernel32.lib
includelib e:\masm32\lib\user32.lib
includelib e:\masm32\lib\ws2_32.lib

.data
caption db "masm wsadata test",0
message db "masm wsadata test",0
wsaData   WSADATA <>

.code
start:
    invoke MessageBoxA,NULL,offset caption,offset message,MB_OK
    invoke WSAStartup,0101h,ADDR wsaData
    invoke WSAStartup,0101h,offset wsaData
    invoke ExitProcess,0
end start
E:\wsadatatest>makeit.bat
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: wsadatatest.asm

***********
ASCII build
***********

 Volume in drive E is New Volume
 Volume Serial Number is CEC6-E6A8

 Directory of E:\wsadatatest

12/07/2017  12:33 AM               627 wsadatatest.asm
12/07/2017  12:39 AM             2,048 wsadatatest.exe
12/07/2017  12:39 AM             1,173 wsadatatest.obj
               3 File(s)          3,848 bytes
               0 Dir(s)  94,127,931,392 bytes free
Press any key to continue . . .