Hi. I am using a pointer to a function (procedure), and this is what I have:

func1 PROTO arg1:BYTE, arg2:BYTE
func2 PROTO arg1:BYTE, arg2:BYTE

FUNCPROTO TYPEDEF PROTO arg1:BYTE, arg2:BYTE
FUNCPTR TYPEDEF PTR FUNCPROTO

...

Main proc
  push esi
  mov ebx, OFFSET pfunc
  
  ;Put 0 into esi to call the first proc.
  ;Put 4 into esi for the second proc.
  mov esi, 4
  
  invoke FUNCPTR PTR , 65, 66
  pop esi

  ret
Main endp

This works fine. I'm just wondering if there is a better or more efficient way of using pointers to procs? Thanx
Posted on 2001-06-23 09:20:00 by Zir0
Try :

.code
;function
Func1 PROC
;func1 code
Func1 ENDP

Func2 PROC
;func2 code
Func2 ENDP
.data
; array of function pointers
pfunc     DWORD  Func1, Func2

; define function offset
FUNC1 = 0
FUNC2 = 4
.code
call      pfunc

; or if the function is selected at runtime :
; ebx = function index
call      pfunc[4*ebx]
This message was edited by karim, on 6/23/2001 1:05:56 PM
Posted on 2001-06-23 11:15:00 by karim
Thanx for your help. Looks simpler than what I had. :-)
Posted on 2001-06-23 14:27:00 by Zir0
Ya'all may also want to check out the COM tuts, this is very similar to object virtual function tables. That code may be adaptable to your needs. http://here.is/cominasm
Posted on 2001-06-23 17:51:00 by Ernie