I decided to create a reusable piece of code that will be easily used in as many environments as possible. I chose COM and ATL to be the solution to my problem. This is also a good programming exercise for my rusty COM / C++ skills and I plan to use it as a template for all my future COM objects.
Points of interest:
- error info support by implementing IErrorInfo interface.
- Help in CHM format and context identifiers specified in MIDL source file.
- BSTR manipulation using CComBSTR class provided by ATL.
- IDispatch support, so the component can be used from scripting environments.
- Spelling implementation itself and support for multiple languages (only Romanian and English for now).
To install the COM object just simply run Install.bat
Here is the Excel macro that makes use of NumberSpeller COM object:
Function Spell(n As Currency) As String
'Create the speller object.
Dim s As NumberSpellerLib.speller
Set s = New NumberSpellerLib.speller
Dim o As Object
Set o = s
o.Language = "ro"
Spell = o.Translate(n)