调用 MASM DLL 时找不到入口点

发布于 2024-12-08 09:57:38 字数 2788 浏览 0 评论 0原文

我正在创建简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2024-12-15 09:57:38

尝试使用“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文