1. C # code
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Runtime. InteropServices;
Using System. Security. Cryptography; namespace ComTest
{
[Guid ("DE03FB14-23D6-4be0-93EA-C27651A22A37")]
Public interface ITest
{
String Test (string test );
}
[Guid ("0ED3C99A-6EBB-4df5-B03F-16CACE242C67")]
Public class CTest: ITest
{
Public string Test (string test)
{
Return test;
}
}
}2. AssemblyInfo. cs File Settings
[Assembly: ComVisible (true)] must be set to True
[Assembly: AssemblyVersion ("1.0.0.0")] must be specified explicitly. The * number cannot be used.
[Assembly: AssemblyKeyFile (@ "c: keyfile. snk")]
Note: c: keyfile. snk is generated by sn-k c: keyfile. snk3. Generate a tlb File
Use Ctrl + Shift + B to generate the DLL file, and then use tlbexp ComTest. dll/out: ComTest. tlb to obtain the. tlb file.4. Register tlb as com
Use C: WINDOWSMicrosoft. NETFrameworkv2.0.50727RegAsm/tlb: ComTest. tlb ComTest. dll/CodeBase5. Add it to the global cache (not required. It is not recommended)
Gacutil-I ComTest. dll
GetKey. bat (get the KeyFile batch processing ):
Path E: Program FilesMicrosoft Visual Studio 8SDKv2. 0in
Sn-k c: keyfile. snkRegCom. bat (generate tlb and register it as a com batch ):
Path E: Program FilesMicrosoft Visual Studio 8SDKv2. 0in
Tlbexp C: DownloadsComTestComTestComTestinReleaseComTest. dll/out: C: DownloadsComTestComTestComTestinReleaseComTest. tlb
C: WINDOWSMicrosoft. NETFrameworkv2.0.50727RegAsm/tlb: C: DownloadsComTestComTestComTestinReleaseComTest. tlb C: DownloadsComTestComTestComTestinReleaseComTest. dll/CodeBase