News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Calling functions in DLL files.

Started by Lightman, December 09, 2015, 08:12:34 PM

Previous topic - Next topic

Lightman

Hello Everyone,

Following Iczelion's Tutorial 17 shows me how to create and use a DLL file, which is cool. The implementation of which goes something like this...


...
; Load up the Library...
invoke   LoadLibrary, addr myLibrary
mov     hLib, eax

; Get the address of the function I'd like to call
invoke   GetProcAddress, hLib, addr myfunction
mov   FuncAddress, eax

; run it...
call   [FuncAddress]

; Clear up when I'm done.
invoke   FreeLibrary, hLib
 

..which is all good. I complete the tutorial and it all works. So, moving on I get to Tutorial 24. In this case I need to use a DLL file again for Windows Hooks. But this time, when coding the program that calls the DLL file, things are a little different. This time Iczelion has two extra files... a .inc and a .lib.. They are with the other libraries that an assembler program might call. When calling the functions from the DLL file, Iczelion is using invoke rather than call.

The .inc file is a text file containing the function prototypes, but the .lib appears to be compiled. Where did he get that file from? This seems to be a much easier way of handling DLLs I have created, but how is this done?

Regards,

Lightman

TWell

link.exe with -dll generate import-library for you.

Lightman

Ah, cool. I'm a RadASM user, so my my linker entry looks like this from the Project->Project Options... Menu (DLL Release Settings)...

/SECTION:.bss,S /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /DLL /DEF:$D /OUT:$O $C $M $R -dll

...and it works. Many thanks.
Regards,

Lightman

TWell

#3
That /DLL is same option as -dll so you can remove last one

EDIT: If someone needs undecorated names in dll , use DEF-file and don't use keyword EXPORT in asm-file
EXPORTS
TestF = _TestF@0

dedndave

the windows API's are also in DLL's
the best way to create import libraries is to use Erol's tools

http://www.vortex.masmcode.com/

in particular, the Def2Lib program is useful for this
Erol's tool creates smaller import libraries

Dll2Inc is another useful tool
it creates DEF and INC files from a DLL

six_L

for ex.


proto_PGetRawInputData typedef proto stdcall :HRAWINPUT,:DWORD,:LPVOID,:PUINT,:DWORD
PGetRawInputData typedef ptr proto_PGetRawInputData

.data?
_GetRawInputData PGetRawInputData ?

.code

GetApiAdd proc dllname:DWORD,procname:DWORD
Local hdll:HWND

invoke LoadLibrary,dllname
.if eax!=0
mov hdll,eax
invoke GetProcAddress,hdll,procname
push eax
invoke FreeLibrary,hdll
pop eax
.endif
ret
GetApiAdd endp

invoke GetApiAdd,CTXT("User32.dll"),CTXT("GetRawInputData")
.if eax==0
mov _GetRawInputData,eax
invoke ErrorMessage,CTXT("GetRawInputData")
.else
mov _GetRawInputData,eax
.endif
....
invoke _GetRawInputData,lParam,RID_INPUT,NULL,addr dwSize,sizeof RAWINPUTHEADER

Say you, Say me, Say the codes together for ever.