News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DLL creation!!! help

Started by xandaz, April 26, 2012, 12:27:30 AM

Previous topic - Next topic

xandaz

   How does one make a Dll or lib in the way that it doesnt go included in the executable but it's loaded at when the process is created. Ive tried several things. I thought i'd just mention the subsystem:windows and it's work that way. can someone help me? Throw some example with the compiling options if it can be. Do i need to register the dll?
   Thanks

MichaelW

Normally, to do Load-Time Dynamic Linking you would link your app with an import library for the DLL.
Dll.asm:

;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================
.data
.code
;==============================================================================
DllMain proc hinstDLL:HINSTANCE, fdwReason:DWORD, lpvReserved:LPVOID
    SWITCH fdwReason
        CASE DLL_PROCESS_ATTACH
            print "DLL_PROCESS_ATTACH",13,10
            ;--------------------------------------------------------------
            ; For DLL_PROCESS_ATTACH we must return TRUE, as otherwise the
            ; system will terminate the process with an error.
            ;--------------------------------------------------------------
            mov eax, 1
        CASE DLL_PROCESS_DETACH
        CASE DLL_THREAD_ATTACH
        CASE DLL_THREAD_DETACH
    ENDSW
    ret
DllMain endp
;==============================================================================
Proc1 proc arg:DWORD
    mov eax, arg
    ret
Proc1 endp
;==============================================================================
end DllMain

Test.asm:

;==============================================================================
include     \masm32\include\masm32rt.inc
includelib  dll.lib
;==============================================================================
Proc1 PROTO Proc1 :DWORD
;==============================================================================
.data
.code
;==============================================================================
start:
;==============================================================================
    invoke Proc1, 123
    printf("%d\n\n", eax)

    inkey
    exit
;==============================================================================
end start

Make.bat:

:
: Assemble dll.asm to create dll.obj.
:
\masm32\bin\ml /c /coff dll.asm
pause
:
: Link dll.obj with the libraries specified in the object
: module to create dll.dll. The /EXPORT option will cause
: the procedure to be exported, and cause the linker to
: create the import library dll.lib, with no need to first
: create a .DEF file.
:
\masm32\bin\Link /VERBOSE /EXPORT:Proc1 /DLL dll.obj
pause
:
: Assemble test.asm to create test.obj.
:
\masm32\bin\ml /c /coff test.asm

pause
:
: Link test.obj with the libraries specified in the
: object module to create the console app test.exe.
:
\masm32\bin\Link /VERBOSE /SUBSYSTEM:CONSOLE test.obj
pause

eschew obfuscation

xandaz

   Well... i did as you explained but Olly doesn't show my dll on the executable modules. Also i think there are problems when freeing the library. Damn.

xandaz

    Oh yeah.... its working... still problems when freeing the lib i think.