Author Topic: Very simple LoadLibrary/GetProcAddress/FreeLibrary Example.  (Read 130 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5338
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
I did this small example for another context but its useful code to know. Because the "invoke" call is a MASM macro it can directly use the address from GetProcAddress.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL hLib  :QWORD                                  ; loal handle for DLL
    LOCAL mbox  :QWORD                                  ; local handle for procedure

    mov hLib, rv(LoadLibrary,"user32.dll")              ; load the DLL
    test rax, rax                                       ; test if it exists
    jnz @F
    .exit                                               ; exit on zero if it does not
  @@:

    mov mbox, rv(GetProcAddress,hLib,"MessageBoxA")     ; get the procedure address
    test rax, rax                                       ; test if it exists
    jnz @F
    .exit                                               ; exit on zero if it does not
  @@:

  ; ------------------
  ; call the procedure
  ; ------------------
    invoke mbox,0,"Win64 : LoadLibrary : GetProcAddress", \
                " Isn't MASM Beautiful",MB_OK

    invoke FreeLibrary,hLib                             ; release the library

    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: