C + + and C # write calls to COM components

Source: Internet
Author: User

A while ago in the work of the project, encountered the COM components of the call and use problems, then research and good for a while, before the middle of the link through, now write to provide convenience for everyone, here contains four types:

1. In VS2005, C # writes DLLs and uses C + + to call

2. COM components written in C # in VS2005, using VC6.0 to invoke

3. Write COM components in VC6.0 and use VS2005 C # to invoke

4, write COM component in VC6.0, use VC6.0 call

Each of these types is written with two programs, one for COM component programs and one for calling programs

Program implementation:

1. In VS2005, C # writes DLLs and uses C + + to call

(1) C # Write DLL program

Establish C # written DLL program Adddll, the project type is: Class Library

Program code:

using System;
using System.Collections.Generic;
using System.Text;
namespace AddDll
{
  public class Add
  {
    public int iadd(int a, int b)
    {
      int c = a + b;
      return c;
    }
  }
}

(2) C + + write the calling program

Establish C + + WIN32 Console application Usedll, the project type is: Win32 Console Application

Configuration: Right-click Usedll in Solution Explorer, select Properties, and set common language runtime support to common language runtime support (/clr)

Figure one common language runtime settings

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.