开发者

How to invoke a pointer to a function in MASM

So I'm trying to invoke a pointer to a function, but I'm failing. Could somebody please help?

I'm storing the function pointer like so:

mov pFunction,offset Function

I can actually get the call to work by doing this:

call pFunction

But when I try this:

invoke pFunction

I get "error A2190: INVOKE requires prototype for pr开发者_运维问答ocedure".

And if I try this:

invoke Function pFunction

I get "error A2206: missing operator in expression".

Any ideas?

PS: here is the whole listing:

.386
.model flat,stdcall
    option      casemap: none
    include     d:\masm32\include\windows.inc
    include     d:\masm32\include\kernel32.inc
    includelib  d:\masm32\lib\kernel32.lib

    Function proto
.data?
    pFunction   dd      ?
.code
start:
    mov pFunction,offset Function
    invoke  pFunction

    push    0
    call    ExitProcess

Function proc
    ret
Function endp
end start


I just found the answer here

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_07.htm

This is what you have to do:

.386
.model flat,stdcall
    option      casemap: none
    include     d:\masm32\include\windows.inc
    include     d:\masm32\include\kernel32.inc
    includelib  d:\masm32\lib\kernel32.lib

    FUNCPROTO       TYPEDEF PROTO 
    FUNCPTR         TYPEDEF PTR FUNCPROTO
.data?
    pFunction   FUNCPTR     ?
.code
start:
    mov pFunction,offset Function
    invoke FUNCPTR ptr pFunction

    push    0
    call    ExitProcess

Function proc
    ret
Function endp
end start
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜