I. Prerequisites for the com callable class
1. Create a class library project
2. In. netCodeExplicitly defines an interface and implements it.
For the COM Client, implementing functions through interfaces has a great benefit.
When a CCW (COM callable packaging) is generated,. Net maintains the same interface as the previous version.
This helps prevent the COM Client from being damaged by changes to the. NET Server.
3. Any class visible to the COM Client must be declared as a public class.
The CCW creation tool only defines public-class-based types. The same rule applies to methods, properties, and events that will be used by the COM Client.
4. Set Project Properties
4.1 Application-> assembly information-> check "make assembly com-visible"
4.2 build-> check "register for com InterOP" [Check this option to generate a TLB file after compilation. If it is not released on the local machine, you do not need to check it.]
For. Net that contains classes that will be used by comProgramYou should also consider using the key pair signature. Microsoft calls this signature to an assembly with a strong name. Adding a strong name to the Assembly signature helps. Net ensure that the code in the Assembly has not been changed after the Assembly is published. Although unsigned assemblies can also be called by COM clients, signatures are required for all global assemblies (global assemblies will be shared by multiple clients ).
II. Use the. NET Framework SDK's Assembly registration tool (regasm) to create and register a Type Library. For example:
Regasm.exe client. Console. dll/TLB: client. Console. TLB
References:
Interoperability: Call the. NET Component (. NET development (general) technology from the COM ComponentArticle)
Http://msdn.microsoft.com/zh-cn/library/ms973800.aspx
Assembly registration tool (regasm.exe)
Http://msdn.microsoft.com/zh-cn/library/tzat5yw6.aspx