Write COM components in C + + and call with C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.