CCW (COM callable wrapper) is a mechanism provided by vs2005. It can export. Net hosted DLL to a traditional com to facilitate VB6 and ASP calls. Below is a common example:
- 1> Create a General C # class library project in vs2005 and write the code
//// Assume that the space is named cslib2 and the class name is class1 // the blue part is very important. // using system;
Using system. Collections. Generic;
Using system. text;
Using system. runtime. interopservices; namespace cslib2
{
[Classinterface (classinterfacetype. autodual)]
Public class class1
{
PublicInt add (int A, int B)
{
Return (A + B );
}
PublicString mergestring (string a, string B)
{
Return (A + B );
}
}
}
- 2> go to project --> "properties" --> "build" --> select"Register for com InterOP"
- 3> modify [Assembly: comvisible (True)] // The default value is false.
- 4> in Visual Studio 2005 command prompt command line tool, first enter the bin \ DEBUG directory of the project.Regasm cslib2.dll/TLB: cslib2.tlb generates the TLB file,Therefore, in VB6, you can select the TLB file in the form of COM.