News:

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

Loading dll

Started by trodon, August 21, 2006, 03:53:23 PM

Previous topic - Next topic

trodon

.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib

.data
AppName db "DLL Skeleton",0
HelloMsg db "Hello, you're calling a function in this DLL",0
LoadMsg db "The DLL is loaded",0
UnloadMsg db "The DLL is unloaded",0
ThreadCreated db "A thread is created in this process",0
ThreadDestroyed db "A thread is destroyed in this process",0

.code
DllEntry proc hInstance:HINSTANCE, reason:DWORD, reserved1:DWORD
.if reason==DLL_PROCESS_ATTACH
invoke MessageBox,NULL,addr LoadMsg,addr AppName,MB_OK
.elseif reason==DLL_PROCESS_DETACH
invoke MessageBox,NULL,addr UnloadMsg,addr AppName,MB_OK
.elseif reason==DLL_THREAD_ATTACH
invoke MessageBox,NULL,addr ThreadCreated,addr AppName,MB_OK
.else        ; DLL_THREAD_DETACH
invoke MessageBox,NULL,addr ThreadDestroyed,addr AppName,MB_OK
.endif
mov  eax,TRUE
ret
DllEntry Endp
TestHello proc
invoke MessageBox,NULL,addr HelloMsg,addr AppName,MB_OK
ret
TestHello endp
End DllEntry


this is example dll for dll loader, and this is .exe loader for this dll:


.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc

includelib kernel32.lib
includelib user32.lib

.data
LibName db "skeleton.dll",0
FunctionName db "TestHello",0
DllNotFound db "Cannot load library",0
AppName db "Load Library",0
FunctionNotFound db "TestHello function not found",0

.data?
hLib dd ?
TestHelloAddr dd ?

.code
start:
        invoke LoadLibrary,addr LibName
        .if eax==NULL
                invoke MessageBox,NULL,addr DllNotFound,addr AppName,MB_OK
        .else
                mov hLib,eax
                invoke GetProcAddress,hLib,addr FunctionName
                .if eax==NULL
                        invoke MessageBox,NULL,addr FunctionNotFound,addr AppName,MB_OK
                .else
                        mov TestHelloAddr,eax
                        call [TestHelloAddr]
                .endif
                invoke FreeLibrary,hLib
        .endif
        invoke ExitProcess,NULL
end start


i need to know how to load .dll with more then one export and with some resource, like DialogBox etc...

thanks

P1

Read over the MASM Library and use your dll the same way.

The batch files in m32lib will help you automate the dll create and use process.

Regards,  P1  :8)

trodon

ok, thanks i will look :U

trodon

QuoteThe batch files in m32lib will help you automate the dll create and use process.

i dont understand how this can help me to make exe file that load my dll file with multi exports
can you give me some example etc.?




P1

trodon,

Sorry to confuse you.  What I meant to add was, use a Library instead of using a dll.  A easier way for support code.

Otherwise, Google for the tools to automate the support files for your MyDll.dll.  Vortex has some Dll tools.
http://www.vortex.masmcode.com/

include \masm32\include\MyDll.inc

includelib \masm32\lib\MyDll.lib
So you can invoke your dll functions from your code.

Regards,  P1  :8)


Vortex

Trodon,

Hutch wrote a nice tutorial about DLLs, have a look at :

How to build a DLL in MASM32

http://website.masm32.com/dlltute/masmdll.htm