Use C ++ to write COM components and use C # To call

Source: Internet
Author: User

Use C ++ to write COM components and use C # To call

1,It is especially important to open vs as an administrator. Otherwise, it will fail.

2. Create a c ++ ATL project, all of which are set by default.

3. Add an ATL simple object and add it from the add class,

4. Add a method. Note that the method is added to the Class View, and the rest are default.

5. Add the code to the test. cpp file to generate the code. A com component is created. <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4NCjxwcmUgY2xhc3M9 "brush: java;"> STDMETHODIMP Ctest: Add (LONG a, LONG B, LONG * c) {// TODO: Add the implementation code here * c = a + B; return S_ OK ;}

6. Add reference in c # To the generated dll file path.

Reference:

7. Add and run the code

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 (. add (4, 7 ));}}}

 

Related Article

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.