News:

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

New macro

Started by donkey, March 11, 2009, 07:44:39 PM

Previous topic - Next topic

donkey

I have become very tired of playing with DispGetParam and it's overly complex parameters. It has to be the most complicated API I have run into what with coercing types, invalid types in the VARIANT passed to it etc..., I think I have spent more times correcting errors in the call than processing any results that I got. Anyway I decided to do it the GoAsm way and it's much simpler. This macro will be in macros.a in the next release of the header project but for now you can add it yourself. It is extremely simple to use, simply pass the address of pdispparams from an IDispatch::Invoke event sink or handler and an integer of the argument number. As with rgvarg from C++ the parameters are returned in reverse order so for n arguments arg n is 0, arg 0 is n-1 (the index is zero based). The function returns a pointer to the VARIANT at that arg location. For example:

void NavigateError(     
    IDispatch *pDisp,
    VARIANT *URL,
    VARIANT *TargetFrameName,
    VARIANT *StatusCode,
    VARIANT_BOOL *Cancel
);


In the following dispatch *Cancel would be argument 0, *pDisp would be 4. This has nothing to do with making it closer to the C++ function but is a result of the way DISPPARAMS stores the arguments.

Now, here's the macro...

#IFNDEF rgvarg
rgvarg(%pdisp,%narg) MACRO
mov eax,%pdisp
mov eax,[eax]
add eax,16*%narg
ENDM
#ENDIF


An example of usage with the dispatch above.

rgvarg([pdispparams],0)

Returns the VARIANT for *Cancel, since it is a pointer it has to be dereferenced so to use the returned VARIANT, the full code would be:

rgvarg([pdispparams],0)
mov eax,[eax+VARIANT.byref] // this is by reference so the initial VARIANT has a pointer to the actual VARIANT

// Fill the VARIANT with our values, VARIANT_TRUE cancels navigation
mov W[eax],VT_BOOL
mov W[eax+VARIANT.boolVal],VARIANT_TRUE
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable