Experiment using a built interface for Office
Building office headers
Using visual studio 2015
- Create a new C++ console application, no precompiled headers
- add the following to the top of the file:
#import "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\MSO.DLL"
#import "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
#import "C:\Program Files (x86)\Microsoft Office\Office15\MSWORD.OLB" \
auto_rename, \
raw_native_types, \
rename("ExitWindows","MsoExitWindows"), \
rename("FindText","MsoFindText"), \
named_guids
See https://msdn.microsoft.com/en-us/library/298h7faa.aspx for these
attributes. Or search for "MSVC #import Attributes"
The attributes we use:
- auto_rename - Renames C++ reserved words by appending two underscores
(__) to the variable name to resolve potential name conflicts.
- raw_native_types - Disables the use of COM support classes in the
high-level wrapper functions and forces the use of low-level data
types instead. To be compatible with existing code we want to use
BSTR rather than _bstr_t
- named_guids - Tells the compiler to define and initialize GUID
variables in old style, of the form LIBID_MyLib, CLSID_MyCoClass,
IID_MyInterface, and DIID_MyDispInterface.
The files created:
- have wrapped functions that emit C++ exceptions in the style:
- long MoveEnd (
- VARIANT * Unit = &vtMissing,
- VARIANT * Count = &vtMissing );
- and have unwrapped functions (no impl) that do not emit
exceptions in the style:
virtual HRESULT __stdcall raw_MoveEnd (
/*[in]*/ VARIANT * Unit,
/*[in]*/ VARIANT * Count,
/*[out,retval]*/ long * prop ) = 0;
Note use _variant_t instead of VARIANT.