MATLAB: How to call a COM object created using MATLAB Builder for .NET 2.0 (R2006a) in a C++ file

activexccomMATLAB Builder NEnet

I have created a COM object using MATLAB Builder for .NET 2.0 (R2006a). I would like an example on calling this from within a C++ file.

Best Answer

An example on doing this is attached here. Note that this example would also work if the COM object was built with MATLAB Builder for COM.
The attached ZIP-file contains 2 MATLAB files (addmatrix.m and transposematrix.m) and a CPP-file (test.cpp). Use the files as detailed below:
1. Execute
mbuild -setup
at the MATLAB command prompt and select a supported C++ compiler such as Microsoft Visual Studio 8.0. Note that the LCC compiler cannot be used to build the component as the version of LCC compiler that ships with MATLAB is a C compiler.
2. Launch DOTNETTOOL by typing
dotnettool
at the MATLAB command prompt.
3. Create a new project by selecting "File -> New Project" menu item and enter the component name as 'myMatrix'. Accept the default class name and project settings.
4. Once you are returned to the MATLAB Builder window, highlight the component, click the "Add File" button and add addmatrix.m and transposematrix.m
5. Select "Build -> COM object" from the menu to build the COM object.
6. Open the CPP-file and observe that addmatrix and transposematrix are invoked as methods of the COM object.