Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sink COM events without mapping dispids manually to methods

I have an IConnectionPointContainer and know the connection point whose events I want to sink. Now I need to write a class containing callback methods for these events.

So basically I am doing this:

OleCheck((ExtIntf as IConnectionPointContainer).FindConnectionPoint(IID_IEvents, cp));
OleCheck(cp.Advise(MySink {<--this one I need}, Cookie));

I need to provide MySink and I know how to do it so that MyIntf.Invoke gets called. But I don't want to map dispids to event methods by hand.

That means I don't want to do this in my Invoke:

// Handle the event
case DispID of
  102   :  OnStatusTextChange(pdpParams^.rgvarg^[lpDispIds[0]].bstrval);
  104   :  OnDownloadComplete;
  105   :  OnCommandStateChange(pdpParams^.rgvarg^[lpDispIds[0]].lval,
                                pdpParams^.rgvarg^[lpDispIds[1]].vbool);
  106   :  OnDownloadBegin;
  108   :  OnProgressChange(pdpParams^.rgvarg^[lpDispIds[0]].lval,
                            pdpParams^.rgvarg^[lpDispIds[1]].lval);
  112   :  OnPropertyChange(pdpParams^.rgvarg^[lpDispIds[0]].bstrval);
  {... doh}

For the connection point IID_IEvents I have both the interface IEvents and the dispinterface declaration (from Delphi type library import). Can't I just implement IEvents somehow? I want a clean class containing methods each one being a callback for one of the events offered by the IID_IEvents connection point.

I have great hope that somebody knows maybe

  • a base class I can inherit from that takes the job of calling my event methods
  • a Delphi wizard that creates the proper class for me
  • the tree I need to make my magic wand of to eventually master COM

Any tips?

like image 466
Heinrich Ulbricht Avatar asked Dec 14 '25 01:12

Heinrich Ulbricht


1 Answers

TechVanguards has a tool that generates the code for you: COM Sink Event Generator.

You can also see my question; where i moaned about having to write what you're faced with writing.

like image 74
Ian Boyd Avatar answered Dec 15 '25 17:12

Ian Boyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!