I have seen this done but I just plain forget how its done. When you have an address of a function and know the number and size of the parameters, what I need to do is write a prototype for it but I could not get it to work and I forget where I have seen it done.

With a function that has a known start address and for example 2 x DWORD parameters, I need a syntax like,


invoke [address],var1,var2

You can easily use the push/call syntax or alternatively use a macro to do what I am after but from memory there is a way to prototype it and use the standard invoke syntax.

Regards,

hutch@movsd.com
Posted on 2003-01-03 19:00:27 by hutch--
I am sure X-Calibre knows it, but he is banned from this board.
Posted on 2003-01-03 21:44:13 by comrade
I think only works with registers:

mov	eax, [address_of_msgbox]

invoke (type MessageBox) ptr eax, 0, OFFSET szMsgAbout, OFFSET szAppTitle, MB_OK OR MB_ICONASTERISK OR MB_APPLMODAL
Posted on 2003-01-03 21:51:47 by comrade
When you do it with memory variable directly, it will end up calling OFFSET of that variable, as if the variable itself was procedure, not containing address of that procedure.
Posted on 2003-01-03 21:55:03 by comrade
Posted on 2003-01-03 23:04:29 by bitRAKE
I'm assuming you have to get the address at run time. This should work:



include:

LCALL2 TYPEDEF proto :dword,:dword
FCALL2 TYPEDEF PTR LCALL2

DC_QueryInterface EQU FCALL2 PTR DDC_QueryInterface

.data
DDC_QueryInterface label proc
dd 0 ;put the address of your new function here
..........................

invoke DC_QueryInterface,*,*

Using the equate hides the extar pointer syntax.

This make the same code as a jump table except the call is FF not E8.

I did have some scope problems however. This works fine with the main(entrypoint) file, but will not work with other included object code. DDC_QueryInterface has a different address in other object files, and you cant extern equates. COMM was the solution:


include:
DS_EnumAttachedSurfaces EQU FCALL2 PTR DDS_EnumAttachedSurfaces

.data
COMM DDS_EnumOverlayZOrders :dword
^
Put the address of you funtion in this link time created variable. Now you function will have global scope arcoss all obj files.
Posted on 2003-01-04 02:21:32 by ThoughtCriminal
Thanks for the links folks, NaN's solution worked perfectly with the test piece I have here.


mov edx, offset address_var
invoke NAME PTR [edx],parameters etc ...



Regards,

hutch@movsd.com
Posted on 2003-01-04 03:42:27 by hutch--
Yes,NaN's solution is very elegant.

Regards,

Vortex

A small example:




.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

myproto typedef proto :dword,:dword,:dword,:dword
MessageBox equ <myproto ptr eax>

.data
user32 db 'user32.dll',0
msgbox db 'MessageBoxA',0
msg db 'How are you?',0
capt db 'Hello my friend!',0
.data?
hLib dd ?
.code
start:
invoke LoadLibrary,addr user32
mov hLib,eax
invoke GetProcAddress,hLib,addr msgbox
invoke MessageBox,0,addr msg,addr capt,MB_OK
invoke FreeLibrary,hLib
invoke ExitProcess,0
end start



Regards,

Vortex
Posted on 2003-01-04 05:09:37 by Vortex