使用MASM32创建DLL

时间:2013-01-14 11:18:54

标签: dll exe masm32

我在masm32中创建DLL时遇到问题。无论我做什么,输出总是* .exe文件,而不是* .dll。以下代码实际上是由masm32创建的代码 - >代码 - >创建新的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

1 个答案:

答案 0 :(得分:0)

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