COM Expertise needed: COM Callbacks

John Chapman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 26 08:30:37 PDT 2017


On Tuesday, 25 April 2017 at 18:39:56 UTC, Nierjerson wrote:
> void RGB(icRGBColor ic, cSolidColor s)
> {
> 	import main;
> 	EXCEPINFO exception;
> 	uint argErr = 0;
> 	auto iidNULL = IID_NULL;
> 	auto RT = new SafeVariantPtr();
> 	VARIANT[1] paramVars;
> 	DISPPARAMS params = {rgvarg: paramVars.ptr, cArgs: 1, 
> cNamedArgs: 0};
> 	auto ID = s.COMMethodIDs[`RGB`];
> 	paramVars[0].punkVal = ic; paramVars[0].vt = 
> VARENUM.VT_DISPATCH; scope(exit) VariantClear(&paramVars[0]);
> 	auto res = s.iDispatch.Invoke(cast(int)ID, &iidNULL, 0, 
> DISPATCH_PROPERTYPUT, &params, cast(VARIANT*)RT, &exception, 
> &argErr);
> 	assert(res == S_OK, `Could not invoke COM Function 
> cSolidColor.RGB. Error `~to!string(res, 16));
>
> }

When you use DISPATCH_PROPERTYPUT you need to set cNamedArgs and 
rgdispidNamedArgs like so:

   int dispidNamed = DISPID_PROPERTYPUT;
   params.cNamedArgs = 1;
   params.rgdispidNamedArgs = &dispidNamed;

You should also call AddRef on any COM objects you add to your 
paramVars array.


More information about the Digitalmars-d-learn mailing list