【问题标题】:Creating DLL using MASM32使用 MASM32 创建 DLL
【发布时间】:2013-01-14 11:18:54
【问题描述】:

我在 masm32 中创建 DLL 时遇到问题。无论我做什么,输出始终是 *.exe 文件,而不是 *.dll。下面的代码其实就是masm32 -> Code -> Create New DLL 创建的。我只是使用 Project -> Build All 来构建它。我做错了什么?

mydll.def

LIBRARY mydll
EXPORTS my_proc
; EXPORTS [your_exported_proc_name]

makeit.bat

@echo off
if exist mydll.obj del mydll.obj
if exist mydll.dll del mydll.dll
\masm32\bin\ml /c /coff mydll.asm
\masm32\bin\Link /SUBSYSTEM:WINDOWS /DLL /DEF:mydll.def mydll.obj 
del mydll.obj
del mydll.exp
dir mydll.*
pause

mydll.asm

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
    include \masm32\include\windows.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    ; -------------------------------------------
    ; Build this DLL with the provided MAKEIT.BAT
    ; -------------------------------------------

      .data?
        hInstance dd ?

      .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

LibMain proc instance:DWORD,reason:DWORD,unused:DWORD 

    .if reason == DLL_PROCESS_ATTACH
      mrm hInstance, instance       ; copy local to global
      mov eax, TRUE                 ; return TRUE so DLL will start

    .elseif reason == DLL_PROCESS_DETACH

    .elseif reason == DLL_THREAD_ATTACH

    .elseif reason == DLL_THREAD_DETACH

    .endif

    ret

LibMain endp

My_proc proc 

    ret

My_proc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

  comment * -----------------------------------------------------
          You should add the procedures your DLL requires AFTER
          the LibMain procedure. For each procedure that you
          wish to EXPORT you must place its name in the "mydll.def"
          file so that the linker will know which procedures to
          put in the EXPORT table in the DLL. Use the following
          syntax AFTER the LIBRARY name on the 1st line.
          LIBRARY mydll
          EXPORTS YourProcName
          EXPORTS AnotherProcName
          ------------------------------------------------------- *

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end LibMain

【问题讨论】:

  • 使用链接器的 /OUT 选项来命名文件。
  • 所以只是名字?我可以手动将.exe 更改为.dll,它会工作吗? xD
  • 事实上 .exe 和 .dll 文件的可移植可执行文件格式是相同的。 .exe 文件也可以像 .dll 文件一样导出函数并动态加载到另一个进程中。一个典型的区别是 .dll 文件没有入口点(但可以有初始化)

标签: dll exe masm32


【解决方案1】:

如果您有 Visual Studio 的许可证,那么您可以使用 Visual Studio 进行 masm32 编程,按照提供的步骤转到项目属性并在配置属性更改下,可以找到如何设置 Visual Studio 的详细信息here配置类型为动态库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多