Author Topic: LoadLibrary, GetProcAddress, FreeLibrary  (Read 16499 times)

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: LoadLibrary, GetProcAddress, FreeLibrary
« Reply #30 on: November 08, 2015, 09:35:27 PM »
i think this is the code i want to use - no FreeLibrary call until exit
now, to devise a test to see if there's a leak in the event they don't clean-up   :redface:

Code: [Select]
    INVOKE  GetModuleHandleA,offset __szKernel32
    .if !eax
        INVOKE  LoadLibraryA,offset __szKernel32
        mov     __hKernel32Free,eax
    .endif

    .if eax
        ;get proc addresses, here
    .else
        dec     eax
        ;set proc address pointers to -1, signifying initialized, unsupported
    .endif

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: LoadLibrary, GetProcAddress, FreeLibrary
« Reply #31 on: November 09, 2015, 05:22:34 AM »

The GetModuleHandle retrieve the loaded module without the loadlibrary.
The getprocadress work.
You use that at your own risk,because the getprocadress failed if the module is unloaded by the module
using it.
This is shown by a test dll loaded only once.
If there is a poor chance to unload the kernel32.dll,it is not the same for other.
Fa is a musical note to play with CL