Here is how to create a .Net object so that it can be used by a COM client:
First you need to create a COM Callable Wrapper (CCW) so that your .NET object can be exposed to COM clients. The CCW is basically a proxy that allows the COM object (unmanaged code) to invoke the .NET object (managed code).
Next, you need to code an interface and a public class that implements the interface. Make sure any methods, properties, and events that you would like to expose to the COM client are also declared public.
Then, you should give your assemblies a strong name (this is a requirement if you are going to make this a Global Assembly.) This gives your .NET assembly a unique name so that it can be identified by your COM client. Create a cryptographic key file using the sn tool. The “-k” creates the .snk file:
sn -k MyNETComponent.snk
Alternatively, you could use Visual Studio to sign your assembly:
1) In the Solution Explorer, right click on the properties of your project. Select the “Signing” tab:
2) Click on “Sign the assembly”. In the “Choose a string name file” select whether this is a new key or browse for an existing key. If you select “New Key” a pop up window will prompt you to enter the Key file name and a password:
3) If you already have a key, just browse to the key’s location.
Here is how to deploy your .NET assembly for COM usage:
1) Create and register your type library using the regasm Assembly Registration Tool:
regasm /tlb:MyNETComponent.tlb MyNETComponent.dll
2) Install your .NET assembly into the GAC Global Assembly Cache using the gacutil tool:
gacutil /i MyNETComponent.dll
No comments:
Post a Comment