Author Topic: Alternative invoke macro  (Read 1908 times)

Vortex

  • Member
  • *****
  • Posts: 2090
Alternative invoke macro
« on: September 14, 2016, 04:58:45 AM »
An alternative macro for 32-bit programming. It does not require functions prototypes and registers can be specified instead of function names. The same macro works with HJWasm and Masm.

A quick example :

Code: [Select]
include     ..\MessageBox.inc

.data

msg         db '_invoke macro test',0
capt        db 'Test',0
MsgBox      db 'MessageBoxA',0
user32      db 'user32.dll',0

.data?

hLib        dd ?

.code

start:

    _invoke  LoadLibrary,ADDR user32
    mov     hLib,eax

    _invoke GetProcAddress,eax,ADDR MsgBox

    _invoke eax,0,ADDR msg,ADDR capt,MB_OK

; without the _invoke macro :

;   invoke pr4 PTR eax,0,ADDR msg,ADDR capt,MB_OK

    _invoke FreeLibrary,hLib

    _invoke ExitProcess,0

END start

Vortex

  • Member
  • *****
  • Posts: 2090
Re: Alternative invoke macro
« Reply #1 on: September 14, 2016, 08:07:51 PM »
A trick for the auto-declaration of external functions and creating import libraries from system DLLs.

Modifying invoke.inc :

Code: [Select]
IFNDEF funcname

    EXTERN funcname:PROC

ENDIF

Building the import libraries :

Code: [Select]
\PellesC\bin\polib /OUT:kernel32.lib /MACHINE:X86 %windir%\system32\kernel32.dll

\PellesC\bin\polib /OUT:user32.lib /MACHINE:X86 %windir%\system32\user32.dll

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6958
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Alternative invoke macro
« Reply #2 on: September 14, 2016, 10:16:09 PM »
 :biggrin:

Erol,

This looks like a piece of genius. I will have to give this a try. Gratsie.  :t

IFNDEF funcname
    EXTERN funcname:PROC
ENDIF
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: