News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A "strongly typed" callback

Started by italogomes, April 18, 2011, 01:38:32 PM

Previous topic - Next topic

italogomes

Hello everyone.

I have been making good progress in my journey with MASM32.  :bg

To enhance my sprite engine, I would like it to have some callback functions that would be registered in the starting process of the game and called when necessary.

So, I was wondering if the compiler could help me in the register task, that is, to not let invalid addresses to be passed to the engine.

Is that possible to have some kind of strongly-typed check?

I would like something similar, but to check that only "compatible" proc addresses would be passed. Say, if the callback requires 2 DWORDs and 1 BYTE, I could not use a "void" proc address as the callback.

If not, well, that's OK (would be just like the old days anyway...)

Thank you all for the great community.

redskull

With a little massaging, you can get INVOKE to check indirect arguments at assemble time.  The following invokes something indirectly through a pointer, but makes sure all the arguments are in order:

.386
.model flat, stdcall
option casemap :none   ; case sensitive


foosig typedef PROTO a1:DWORD, a2:DWORD
fooptr typedef PTR foosig

fooproc  PROTO foosig


.code

start:

mov eax, OFFSET fooproc
invoke fooptr PTR [eax], 42     ; missing an arugment!


fooproc  PROC a1:DWORD, a2:DWORD
    ret
fooproc ENDP

end start




-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

italogomes