调用 MASM DLL 时找不到入口点
我正在创建简单的 masm DLL :
; #########################################################################
.386
.model flat, stdcall
option casemap :none
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
; #########################################################################
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM
m2m MACRO M1, M2
push M2
pop M1
ENDM
return MACRO arg
mov eax, arg
ret
ENDM
.code
; ##########################################################################
LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD
szText LmTitle,"tstdll's LibMain Function"
.if reason == DLL_PROCESS_ATTACH
szText ATTACHPROCESS,"PROCESS_ATTACH"
invoke MessageBox,NULL,ADDR ATTACHPROCESS,addr LmTitle,MB_OK
return TRUE
; -----------------------------
; If error at startup, return 0
; System will abort loading DLL
; -----------------------------
.elseif reason == DLL_PROCESS_DETACH
szText DETACHPROCESS,"PROCESS_DETACH"
invoke MessageBox,NULL,addr DETACHPROCESS,addr LmTitle,MB_OK
.elseif reason == DLL_THREAD_ATTACH
szText ATTACHTHREAD,"THREAD_ATTACH"
invoke MessageBox,NULL,addr ATTACHTHREAD,addr LmTitle,MB_OK
.elseif reason == DLL_THREAD_DETACH
szText DETACHTHREAD,"THREAD_DETACH"
invoke MessageBox,NULL,addr DETACHTHREAD,addr LmTitle,MB_OK
.endif
ret
LibMain Endp
; ##########################################################################
CRC16 proc ; can't find entry point :(
szText crcmsg,"TestMsg"
invoke MessageBox,NULL,addr crcmsg,addr LmTitle,MB_OK
ret
CRC16 endp
; ##########################################################################
End LibMain
并用于
\masm32\bin\ml /c /coff crc16.asm
\masm32\bin\Link /SUBSYSTEM:WINDOWS /DLL /DEF:crc16.def crc16.obj
创建 DLL,其中 crc16.def 是:
LIBRARY CRC16.DLL
EXPORTS
CRC16
我正在调用并运行它:
[DllImport("crc16.dll", EntryPoint = "crc16", CharSet = CharSet.Ansi, ExactSpelling = true, PreserveSig = true)]
unsafe private static extern void crc16();
unsafe private void button1_Click(object sender, EventArgs e)
{
crc16();
}
但我的程序失败并显示消息:找不到入口点“crc16”
我做错了什么?
I'm creating simply masm DLL :
; #########################################################################
.386
.model flat, stdcall
option casemap :none
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
; #########################################################################
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM
m2m MACRO M1, M2
push M2
pop M1
ENDM
return MACRO arg
mov eax, arg
ret
ENDM
.code
; ##########################################################################
LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD
szText LmTitle,"tstdll's LibMain Function"
.if reason == DLL_PROCESS_ATTACH
szText ATTACHPROCESS,"PROCESS_ATTACH"
invoke MessageBox,NULL,ADDR ATTACHPROCESS,addr LmTitle,MB_OK
return TRUE
; -----------------------------
; If error at startup, return 0
; System will abort loading DLL
; -----------------------------
.elseif reason == DLL_PROCESS_DETACH
szText DETACHPROCESS,"PROCESS_DETACH"
invoke MessageBox,NULL,addr DETACHPROCESS,addr LmTitle,MB_OK
.elseif reason == DLL_THREAD_ATTACH
szText ATTACHTHREAD,"THREAD_ATTACH"
invoke MessageBox,NULL,addr ATTACHTHREAD,addr LmTitle,MB_OK
.elseif reason == DLL_THREAD_DETACH
szText DETACHTHREAD,"THREAD_DETACH"
invoke MessageBox,NULL,addr DETACHTHREAD,addr LmTitle,MB_OK
.endif
ret
LibMain Endp
; ##########################################################################
CRC16 proc ; can't find entry point :(
szText crcmsg,"TestMsg"
invoke MessageBox,NULL,addr crcmsg,addr LmTitle,MB_OK
ret
CRC16 endp
; ##########################################################################
End LibMain
And using
\masm32\bin\ml /c /coff crc16.asm
\masm32\bin\Link /SUBSYSTEM:WINDOWS /DLL /DEF:crc16.def crc16.obj
for creating DLL where crc16.def is :
LIBRARY CRC16.DLL
EXPORTS
CRC16
I'm invoking and run it :
[DllImport("crc16.dll", EntryPoint = "crc16", CharSet = CharSet.Ansi, ExactSpelling = true, PreserveSig = true)]
unsafe private static extern void crc16();
unsafe private void button1_Click(object sender, EventArgs e)
{
crc16();
}
But got my program falling with message : Can't find entry point "crc16"
what am I doing wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用“CRC16”而不是“crc16”。
另外,将 DLL 文件加载到 PEInfo 等工具中,并检查导出的名称是否正确。有时编译器会破坏名称。
Try "CRC16" instead of "crc16".
Also, load the DLL file into a tool like PEInfo and check that the exports are named correctly. Sometimes the compiler mangles the names.