COM Integration/Writing your own COM component using VC++
Requires Analytica 4.6 Enterprise or better', and Microsoft Visual Studio
Introduction
This article leads you through the steps to create your own COM component in VC++ that can be called from your Analytica model. This provides a mechanism to call your own C++ code from Analytica. You may want to do this when you have an algorithm that you want to make really fast, have pre-existing and complex C++ code that you want to call, or want to create a wrapper to integrate with some other existing component, service or program.
The instructions here use Visual Studio 2013 Update 5. The steps may vary slightly in different Visual Studio releases.
In this introduction, I create a component named Rainfall.Counter
. Your own component name will differ, so make the substitution with your own component name where appropriate. Once completed, the component is used from Analytica by first instantiating the object in an Analytica variable using.
COMCreateObject("Rainfall.Counter")
And then calling its methods from other within the Definition of other variables. The methods of this class accept a one-dimensional array as input and return a one-dimensional array as a result.
Create the Project
Start by creating a Visual Studio project. Launch VS and select File / New / Project… / Templates / Visual C++ / ATL / ATL Project.
Enter a name for your project -- my project is named Rainfall
. Press OK. On the next screen, set the application type to Executable (EXE) and check Allow merging of proxy/stub code.
The proxy/stub is for convenience, eliminating an extra DLL that would otherwise have to be distributed with your final solution. The other Application types can also be used, but if you aren't sure why you'd want them, stick with EXE.
Once you press Finish, your initial project is created.
Configuring to be 64-bit
You may optionally configure your component to be 64-bit. A few factors come into play in making this decision. If you are using C++ for pure algorithmic speed, then I recommend building a 64-bit component, since 64-bit applications tend to run about 50% faster than 32-bit ones. In addition, your component will be able to access large amounts of memory, should that be needed. However, your 64-bit component will not be usable by someone with a 32-bit Windows operating system. If your component is a wrapper for another application, or if you are wrapping an existing third-party library, then you may need to match the bitness of your available database drivers, application drivers and libraries.
To configure to be 64-bit, select Build / Configuration Managerߪ. In the pulldown for Platform, select <Newߪ>
. Set New platform=x64, copy settings from=Win32 and press OK. It should now look like this.
Creating the Object Class
Next, create the class that will get instantiated when you call COMCreateObject from Analytica.
Enable comment auto-refresher