tags:

views:

55

answers:

1

I am writing an application that needs to handle events fired by Office - things like 'before print' or 'new file'.

From various articles and examples I understand I should use the IConnectionPoint interfaces. I got the ConnectionPointContainer for Word.Application using QueryInterface.
Now I want to run FindConnectionPoint, but I have to give it the IID of the interface I am looking for, and I don't know where to find that! I thought of running EnumConnectionPoints, but that will give me all the connection points and I don't know how to identify which are the ones I need.

How do I know the IID?

A: 

There're two possible scenarios:

  • you find a description for that event interface somewhere (for example, a .h file describing the interface)
  • you get a type library - either in a separate .tlb file or embedded as a resource into the COM server .dll file and use OleView to read it or #import directive in Visual C++ to import it and get it converted into a C++ interface definition with named constants for IIDs.

You might also use IConnectionPointContainer::EnumConnectionPoints(), then IConnectionPoint::GetConnectionInterface(), but just getting the IID is of no value if you don't know the interface definition in the first place, to one of the above will still be needed.

sharptooth
Your reply together with the one from Hans were very helpful. Nevertheless I'm still stuck :-(. I opened MSWORD.OLB in the OLE viewer, and did indeed find the interfaces I need. The problem is that when I use these in FindConnectionPointer I get a CONNECT_E_NOCONNECTION error. The progID I used to find the ConnectionPointContainer was Word.Application .
rimono
BTW, I also tried to import MSWORD.OLB, but I got compilation errors on msword.tlh. I couldn't find anything else relevant to word that I could import.
rimono
@rimono: You shouldn't use ProgIDs for that, use interface IDs - there should be an interface named something like "WordWhateverCoolThingsEvents" - apply `__uuidof` to it and this will get you the IID.
sharptooth
I admit I am confused by the different IDs. The argument I gave FindConnectionPoint seems to be correct - it is the IID I found in MSWORD.OLB, after running on it IIDFromString. I see in the debugger that it is indeed called IID_IApplicationEvents2, which is what I intended. Maybe the problem is in the ConnectionPointContainer from which I call FindConenctionPointer. I first ran CLSIDFromProgID on 'Word.Application'. I then ran CoCreateInstance on this CLSID with IID_IUnknown, and with the result called QueryInterface for IID_IConnectionPointContainter. Does this make sense?
rimono
@rimono: Looks reasonable so far. Yes, you create a component instance and query it for `IConnectionPointContainter`.
sharptooth
@rimono: Have you looked at this KB article http://support.microsoft.com/kb/309294 ?
sharptooth
I got it to work! I used the IID of a slightly different interface and now it works. I hope this interface gives me the events I need! Thanks for your help!
rimono
@rimono: You're welcome.
sharptooth