News:

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

Could GetProcAddress be called once?

Started by lamer, January 27, 2006, 10:52:21 AM

Previous topic - Next topic

lamer

Hi all!
I load some library at the beginning of program execution and free it on exit.
Is it safe to call GetProcAddress for needed function only once after the library has ben loaded and use the returned value till program ends or I have to call GetProcAddress each time I need to use the function, i.e. - does the procedure address remain the same after loading the library?

Thank you

hutch--

You could try your luck and write a test piece but the conventional wisdom is to unload the DLL on exit, its not like it costs you anything.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Tedd

The function address will not change once it's been loaded - this is the same mechanism that PE imports use, so it has to stay the same.
If you load and unload, and then load again, it's not guaranteed to be the same (though it most likely would be, unless the dll is relocated.)
No snowflake in an avalanche feels responsible.

sluggy

As Tedd said, the dll gets rebased if necessary before you get a handle to it. Any subsequent dll that gets loaded and would have occupied the space currently used by the first dll will also get rebased to another address.

u

To sum it up:

.data
hDLL dd 0
ptrFunc1 dd 0
.code
invoke LoadLibrary,T("mylib.dll")
mov hDLL,eax
invoke GetProcAddress,hDLL,T("Func1")
mov ptrFunc1,eax

; now, ptrFunc1 is always valid:
call ptrFunc1
;....
call ptrFunc1
;....
call ptrFunc1
;..


So, you just need to use GetProcAddress for one function just once :)
Please use a smaller graphic in your signature.