我正在创建简单的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
用于创建crc16.def所在的DLL:
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”
我做错了什么?
答案 0 :(得分:2)
尝试“CRC16”而不是“crc16”。
此外,将DLL文件加载到PEInfo之类的工具中,并检查导出是否正确命名。有时编译器会破坏名称。