Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi 错误LNK2001:未解析的外部符号\u MessageBox_Winapi_Assembly_Masm_Masm32 - Fatal编程技术网

Winapi 错误LNK2001:未解析的外部符号\u MessageBox

Winapi 错误LNK2001:未解析的外部符号\u MessageBox,winapi,assembly,masm,masm32,Winapi,Assembly,Masm,Masm32,我试图创建一个helloworld程序,只使用masm,而不使用masm32库。以下是代码片段: .386 .model flat, stdcall option casemap :none extrn MessageBox : PROC extrn ExitProcess : PROC .data HelloWorld db "Hello There!", 0 .code start: lea eax, HelloWorld mov eb

我试图创建一个helloworld程序,只使用masm,而不使用masm32库。以下是代码片段:

.386
.model flat, stdcall
option casemap :none

extrn MessageBox : PROC
extrn ExitProcess : PROC

.data
        HelloWorld db "Hello There!", 0

.code
start:

        lea eax, HelloWorld
        mov ebx, 0
        push ebx
        push eax
        push eax
        push ebx
        call MessageBox
        push ebx
        call ExitProcess

end start
我能够使用masm组装此组件:

c:\masm32\code>ml /c /coff demo.asm
Microsoft (R) Macro Assembler Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: demo.asm
但是,我无法将其链接:

c:\masm32\code>link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user
32.lib demo.obj
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

demo.obj : error LNK2001: unresolved external symbol _MessageBox
demo.obj : error LNK2001: unresolved external symbol _ExitProcess
demo.exe : fatal error LNK1120: 2 unresolved externals
我在链接期间包含LIB,所以不确定为什么它仍然显示未解析的符号

更新:

c:\masm32\code>link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user
32.lib demo.obj
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

demo.obj : error LNK2001: unresolved external symbol _MessageBox@16
demo.exe : fatal error LNK1120: 1 unresolved externals
更新2:最终工作代码

.386
.model flat, stdcall
option casemap :none

extrn MessageBoxA@16 : PROC
extrn ExitProcess@4 : PROC

.data
        HelloWorld db "Hello There!", 0

.code
start:

        lea eax, HelloWorld
        mov ebx, 0
        push ebx
        push eax
        push eax
        push ebx
        call MessageBoxA@16
        push ebx
        call ExitProcess@4

end start

正确的函数名是
MessageBoxA@16
ExitProcess@4

几乎所有Win32 API函数都是stdcall,因此都带有
@
符号,后跟其参数占用的字节数

此外,当Win32函数接受字符串时,有两种变体:一种是接受ANSI字符串(名称以
a
结尾),另一种是接受Unicode字符串(名称以
W
结尾)。您提供的是ANSI字符串,因此需要
版本


当您不在汇编程序中编程时,编译器会为您处理这些问题。

请尝试在
之前添加此项。data
段:

include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

谢谢这解决了其中一个链接错误,但没有解决另一个。。看到更新了吗!现在工作得很好。我觉得自己就像一个n00b——你能推荐一些我可以从中挑选这些东西的文档/书籍吗?MSDN太让人望而生畏了,当你还是一个新手的时候,你可能还想参考Iczelion的Win32 ASM教程:我喜欢Randall Hyde的东西:。他使用HLA,它实际上是原始MASM之上的一组宏,但原理是一样的。顺便说一句,这些问题不是无关紧要的:对于汇编,您必须处理高级工具通常处理的许多恼人的细节。