1. Open vs as Administrator, especially important, otherwise it will not succeed
2. Create a new C + + ATL project, all the default settings
3. Add an ATL Simple object, added from the Add class,
4. Add a method, note that it is added in Class View, and follow the settings, the rest is the default
5. Then add code to the Test.cpp file to generate it. A COM component is made.
STDMETHODIMP Ctest::a, LONG b, LONG* c){ // TODO: 在此添加实现代码 a + b; return S_OK;}
6. Add a reference in C # to the generated DLL file path.
After the reference:
7. Add code and run
using system;using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using Atlproject1lib; namespace csharpMatlab { class Program { static void Main (
string [] args) {Test a =
new test (); Console.WriteLine (A.add (
4 ,
7 )); } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Write COM components in C + + and call with C #