Sunday, April 17, 2011

Deploying COM-Enabled Assemblies

Although an assembly can be created visible to COM, one should follow below guidelines to ensure that things work as planned:
  • All classes must use a default constructor with no parameters.
  • Any type that is to be exposed must be public.
  • Any member that is to be exposed should be public.
  • Abstract classes will not be able to be consumed.
After these criteria are met, the assembly is essentially ready to be exported. There are two mechnisms to do so. One can use VS or a command line utility(TlbExp.exe). First you need to compile the type through Visual Studio's build mechanism or through command line compiler as
              csc /t:library ComVisiblePerson.cs
Next you need to use Type Library Exporter Utility. This should be done from VS command prompt:
              tlbexp ComVisiblePerson.dll /out:ComVisiblePersonlib.tlb
Next oyu need to create  resource script (ComVisiblePerson.res) with the following Interface Definition Language (IDL) definition:
              IDR_TYPELIB1 typelib "ComVisiblePersonlib.tlb"
then you recompile the application with the new resource file added as:
              csc /t:library ComVisiblePerson.cs /win32res:ComVisiblePerson.res


No comments:

Post a Comment