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 DETACH开发者_开发知识库PROCESS,"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 ?
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.
精彩评论