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
For example CreateFile and MessageBox
Thanks in Advance
Basically
To get the library handle, lpszLibraryName is the name of the DLL.
Then:
lpszProcName is the name of the function you want from the dll.
Lets supposed that procedure have 2 parameters, p0 and p1
to call the procedure.
And finally be sure to use FreeLibrary
to free the library.
Masm32 has an example in:
and the links for the functions in MSDN are:
LoadLibrary
GetProcAddress
FreeLibrary
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
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
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
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.
Time to Get Down with the Boggie.....
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.
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...
You keep it loaded as long as you have to.
;;; 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
;;;;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
just a guess... but perhaps
it's "MessageBoxA" instead of "MessageBox"
it's "MessageBoxA" instead of "MessageBox"
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
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
Thanks Hutch
I forgot about FULL Path. I should have known....
I forgot about FULL Path. I should have known....
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: ).