0

I'm writing a DLL which talks to Excel via its IDispatch interface. From VBA I pass in a Variant containing Application.Caller from which I draw the IDispatch pointer via .pDispVal.

What I'd like to know is how to query the interface via that IDispatch pointer. I want to set up a connection point container, and from there find a connection point to Excel. The ultimate goal is to tie things to Excel's Calculate event and be able to manipulate the Excel data.

bugmagnet
  • 7,631
  • 8
  • 69
  • 131
  • Predominantly the Binh Ly link. – bugmagnet Dec 12 '08 at 02:17
  • Being a bit of a Delphi newbie (in some respects) I'm still a bit in the dark, but there is a light at the end of the tunnel, and I'm fairly sure it's not the headlamp of a fast-approaching train. – bugmagnet Dec 12 '08 at 02:19
  • Yeah, Binh's tutorials used to be the big eye opener about all things COM for me too, some eight years back... – Oliver Giesen Dec 12 '08 at 07:12
  • BTW: When you're talking about "a DLL which talks to Excel" is that actually a COM server or are you somehow using exported functions that you call from VBA? I still have the feeling that you would be better off by implementing the whole thing as a regular addin, possibly dropping the VBA side. – Oliver Giesen Dec 12 '08 at 07:15
  • The issue at hand is to do in Delphi what's already been done in C++ by Herbert Danler with his excelmvf add-in . Once you've had a look at that, tell me if you can still drop the VBA side. – bugmagnet Dec 13 '08 at 03:05

2 Answers2

1

Brian Long explains: http://www.blong.com/Conferences/IConUK2000/DelphiMoreAutomation/More%20Automation%20In%20Delphi.htm#Events

Other resources:

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
1

I would recommend Binh Ly's timelessly excellent (Delphi) COM tutorials at http://www.techvanguards.com/ which includes chapters entirely dedicated to IConnectionPoint and related mechanisms.

He also offers a free tool for generating EventSink code.

Still, I have a strong feeling that this shouldn't be necessary at all if all you want to do is react to an event triggered by the Excel Application object. Have you tried simply using the wrapper objects that the Delphi Type Library importer generates for you? You can of course also write your own wrappers.

Then again, I haven't actually written any addins for Excel yet - but I do write addins for Outlook and Word for a living and Excel really shouldn't be much different in this regard.

Oliver Giesen
  • 9,129
  • 6
  • 46
  • 82