The only thing I know abput is Includes....I have not never used LoadLibrary & GetProcAddress. Could someone give me an example of how to do in masm32.

For example CreateFile and MessageBox

Thanks in Advance
Posted on 2002-01-30 20:36:51 by cmax
Basically



invoke LoadLibrary, addr lpszLibraryName
and eax, eax
jz @@quitError
mov libHandle, eax


To get the library handle, lpszLibraryName is the name of the DLL.

Then:



invoke GetProcAddress, libHandle, addr lpszProcName
and eax, eax
jz @@quit
mov myImportedProcAddress, eax


lpszProcName is the name of the function you want from the dll.

Lets supposed that procedure have 2 parameters, p0 and p1



push p1
push p0
call [myImportedProcAddress]


to call the procedure.

And finally be sure to use FreeLibrary


invoke FreeLibrary, libHandle
and eax, eax
jz @@error
xor eax, eax
mov libHandle, eax


to free the library.

Masm32 has an example in:


c:\Masm32\EXAMPLE1\DLL\CALLDLL


and the links for the functions in MSDN are:
LoadLibrary
GetProcAddress
FreeLibrary
Posted on 2002-01-30 21:06:23 by dxantos
This is a very nice example lay out. I'm going to follow it tonight...

Do this make any since:
When I call LoadLibrary can I also get the raw API # and include that too....... do this mean replace the word LoadLibrary with the API Number.

I am trying to re-write my program in the lowest possible way with masm32. And i think this means putting all numbers directly in the program. I got the time now to waste with this.

Thanks Again
Posted on 2002-01-30 21:28:15 by cmax
When you call GetProcAddress you can specify the APIs ordinal number then you'll have a pointer to it but it is best to use the names because dll may be updated and there ordinal could change.
Posted on 2002-01-30 22:20:36 by Quantum
Time to Get Down with the Boggie.....
Posted on 2002-01-30 22:38:53 by cmax
That's right. The ordinal number is not guaranteed to be the same for all versions of Win32. In fact, many functions had different ordinals between Win95 and NT 3. I have not checked the Win2k and Win98 ordinals.
Posted on 2002-01-30 22:57:42 by tank
When i call LoadLibrary can I keep it until the program is shut down or do you HAVE to call FreeLibrary right after it did it job first job...
Posted on 2002-01-31 00:56:47 by cmax
You keep it loaded as long as you have to.
Posted on 2002-01-31 01:01:54 by gliptic
;;; I been playing with this for hours....I tried both ways but can
;;;;get it working


.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:SWORD

include \MASM32\INCLUDE\windows.inc
;;;; include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc

;;;; includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

MessageBox PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data
MyText db "It's Working",0
; ..................................................................................................

hLib DWORD 0
myImport01 DWORD 0

myImport01 DWORD 0
libHandle DWORD 0

libName db "user32.dll",0
FuncName01 db "MessageBoxA",0
.code
Main:
; ..................................................................................................

invoke LoadLibrary, offset libName
and eax, eax
;;jz @@quitError
mov libHandle, eax

invoke GetProcAddress, hLib, offset FuncName01
and eax, eax
;;jz @@quit
mov myImport01, eax
; ..................................................................................................

; jmp @F
; libName db "user32.dll",0
; FuncName db "MessageBox",0
; @@:

; ..................................................................................................

; invoke LoadLibrary,offset libName
; mov hLib, eax

; invoke GetProcAddress,hLib,offset FuncName01
; call eax
; ..................................................................................................
push 0
push 0
push offset MyText
push 0
call myImport01

invoke FreeLibrary,myImport01

invoke ExitProcess,0
; ........................................................................................................
end Main
Posted on 2002-01-31 04:06:18 by cmax
just a guess... but perhaps
it's "MessageBoxA" instead of "MessageBox"
Posted on 2002-01-31 04:10:45 by Asm_Freak
cmax,

Just test both return values after the two functions. With LoadLibrary() you may have to specify the complete path of USER32.DLL, "c:\windows\system\user32.dll", ensure it has the right return value and then get the address of the procedure you want with GetProcAddress().

Asm_Freak is right, the correct name for that function has an "A" on the end of it to designate that it is an ANSI function so make sure you use the name that occurs in the DLL you are after.

Regards,

hutch@movsd.com
Posted on 2002-01-31 05:02:30 by hutch--
Thanks Hutch

I forgot about FULL Path. I should have known....
Posted on 2002-01-31 05:07:55 by cmax
Well, he shouln't need to specify a path. Since is a system dll it should be available in the path in the firsplace (otherwise windows wont be running :grin: ).
Posted on 2002-01-31 05:34:28 by dxantos