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