2013-01-14 80 views
1

在masm32中創建DLL時遇到問題。不管我做什麼,輸出總是* .exe文件,而不是* .dll。以下代碼實際上是由masm32 - > Code - > Create New DLL創建的代碼。我只是使用Project - > Build All來構建它。我做錯了什麼人?使用MASM32創建DLL

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 
+0

使用鏈接器的/ OUT選項來命名文件。 –

+0

所以這只是名稱?我可以手動將.exe更改爲.dll,它會起作用嗎? xD – user1913596

+1

事實上,對於.exe和.dll文件,Portable Executable格式都是相同的。 .exe文件也可以導出函數,並且可以像.dll文件一樣動態加載到另一個進程中。一個典型的區別是.dll文件沒有入口點(但可以有初始化) –

回答

0

如果您有Visual Studio的許可,則可以使用Visual Studio的你masm32編程,關於如何設置Visual Studio的詳細信息可以在here之後找到提供的步驟轉到項目屬性,並在配置屬性下將配置類型更改爲動態庫。