MATLAB: Can I use a COM object and a .NET object, both created using MATLAB Builder for .NET 2.0 (R2006a), in the Visual Studio project

ccomMATLAB Builder NEnetstudiovisual

I have a Visual Studio project in which I need to use a COM object and a .NET object. Both these objects were built using MATLAB Builder for .NET 2.0 (R2006a).
I would like to know whether I can use both these objects in my project and if I should be aware of any special settings.

Best Answer

It is possible to use a COM object and a .NET object - both generated with MATLAB Builder for .NET 2.0 (R2006a) - in the same project / program in Visual Studio.
If you have code that was earlier compiled into a COM object using MATLAB Builder for COM, you can now compile it into a COM object using MATLAB Builder for .NET. You can then include the .NET object and the COM object in the same program and be able to invoke the methods in your Visual Studio application.
The attached ZIP-file contains
a. A Visual Studio project written in C#
b. 2 MATLAB files - foo.m and bar1.m, used to generate
c. A COM object named foocomponent
d. A .NET object named foo2component
e. A .NET object named bar1component
In order to build and test this application, perform the steps given below using the files extracted from the attached ZIP-file:
1. Execute
mbuild -setup
at the MATLAB command prompt and select a supported C/ C++ compiler such as Microsoft Visual Studio 2005. Note that the LCC compiler cannot be used to build the components.
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 'foocomponent'. 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 foo.m
5. Select "Build -> COM object" menu item to build the COM object.
6. Follow steps 3-5 to generate the two .NET objects (use bar1.m for bar1component and foo.m for foo2component)
7. Open 'ConsoleApplication1' in Visual Studio.
8. In the Solution Explorer tab, right-click on 'ConsoleApplication1' and choose "Add Reference...". Add references to the above 3 components as well as to MWComUtil.
9. Select the "Build -> Build Solution" from the menu and then execute the application. You should see the words 'foo' and/ or 'bar' displayed upon successful execution.