2

I'm lurking through the very few samples of native Word addins available, trying to find the way to reconstruct VSTO's Document.OnBeforeClose event.

Currently, I figured out that IDTExtensibility2 has a reference to DTE, and that DTE is a same COM-based approach used for Visual Studio extensions.. (so if I'll find a working C++-written VS add-in with same kind of hooks, it will solve my problems fast.)

This was taken from TestAddin2 sample from 2000's:

    BEGIN_COM_MAP(CConnect)
            COM_INTERFACE_ENTRY2(IDispatch, IRibbonCallback)
            COM_INTERFACE_ENTRY(IConnect)           
            COM_INTERFACE_ENTRY(_IDTExtensibility2)
            COM_INTERFACE_ENTRY(_FormRegionStartup)
            COM_INTERFACE_ENTRY(IRibbonExtensibility)
            COM_INTERFACE_ENTRY(IRibbonCallback)
    END_COM_MAP()

So currently I wonder:

  • how to acquire a proper ENTRY* parameters for capturing document-level events from within Word?
  • what interface(s) should be implemented to support that?
  • how to properly implement callback functions (ones that are passed to com object as 'handlers' in VSTO) in pure C++ COM?
  • is there anything to generate headers from existing COM object, like VS does when showing COM object fields/props?

It seems that at least someone on SO managed to write a native-code addin (packaging a COM addin for deployment), so I'm really expecting help here.

Community
  • 1
  • 1
kagali-san
  • 2,964
  • 7
  • 48
  • 87

1 Answers1

2

Here is a sample illustrating how to implement event handlers for COM dispinterfaces with ATL's IDispEventImpl/BEGIN_SINK_MAP/SINK_ENTRY_EX/END_SINK_MAP:

http://support.microsoft.com/kb/194179.

To generate COM definitions for MS Word and Office Object Model, you'd need the following files:

MSADDNDR.TLB
MSO.DLL
MSWORD.OLB
VBE6EXT.OLB

You should be able to find them somewhere under "C:\Program Files (x86)\Microsoft Office\". The following import code worked for me a while ago with Office 2007, you may need to tweak it for more recent Office versions:

#import "TypeLib\MSADDNDR.TLB" \
    raw_interfaces_only \
    no_namespace \
    auto_search 

#import "TypeLib\MSWORD.OLB" \
    raw_interfaces_only \
    rename("ExitWindows","MsoExitWindows") \
    rename("FindText","MsoFindText") \
    rename("DocumentProperties", "MsoDocumentProperties") \
    rename("RGB", "MsoRGB") \
    auto_search \
    exclude("IAccessible", "AddIn", "Adjustments") 
noseratio
  • 59,932
  • 34
  • 208
  • 486