Tuesday 23 May 2017

COM Support Classes

Writing C++ code currently to enhance the VBA experience and so I'm dealing with Automation types very frequently. A good VBA ought to know that a VBA string is in fact a BSTR and that a VBA Variant also has a C++ counterpart.

So BSTRs have memory management rules which need to be observed otherwise one will leak memory. Thankfully C++ classes using RAII design patterns can assist. It just seems there are more than one to choose from and it is worth documenting them here on a blog entry.
BSTR helper classesVendorLibraryHeader
_bstr_t ClassMicrosoftNative C++ compiler COM supportcomutil.h
CComBSTR ClassMicrosoftATLatlbase.h


Variant also has helper classes
Variant helper classesVendorLibraryHeader
_variant_t ClassMicrosoftNative C++ compiler COM supportcomutil.h
CComVariant ClassMicrosoftATLatlbase.h


Also found a nice page of sample code demonstrating the Native C++ compiler COM support classes interacting with ADO objects which are normally scripted with VBA and thus have automation-typed interfaces. Visual C++ ADO Programming

Also Stack Overflow question discussing the classes available. Looks like the classes listed above represent the sum of Microsoft options.

No comments:

Post a Comment