Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:creating_com_library [2012/05/14 16:09]
smayr
swdev:dotnet:creating_com_library [2012/05/16 12:40] (current)
smayr [Creating COM Library]
Line 1: Line 1:
 = Creating COM Library = = Creating COM Library =
  
-  * Create a new Class Library project (Eg: MyLib). Start VS2010 as administrator.+  * Create a new Class Library project (Eg: MyLib). Start VS2010 as administrator in order to register types and assemblies.
   * Interface:   * Interface:
     * Add to the file:<code csharp>using System.Runtime.InteropServices;</code>     * Add to the file:<code csharp>using System.Runtime.InteropServices;</code>
Line 20: Line 20:
 }</code> }</code>
     * Add the attributes ''ClassInterface'', ''Guid'', ''ProgId'' to the interface. Generate a Guid using Tools > Generate GUID. <code csharp>     * Add the attributes ''ClassInterface'', ''Guid'', ''ProgId'' to the interface. Generate a Guid using Tools > Generate GUID. <code csharp>
-[InterfaceType(ComInterfaceType.InterfaceIsDual)]+[ClassInterface(ClassInterfaceType.None)]
 [Guid("0BE40A98-FCAC-432D-B0B6-999B42A28E48")] [Guid("0BE40A98-FCAC-432D-B0B6-999B42A28E48")]
 [ProgId("MyLib.MyLauncher")]</code> [ProgId("MyLib.MyLauncher")]</code>
     * ''ProgId'' convention is ''{namespace}.{class}''     * ''ProgId'' convention is ''{namespace}.{class}''
   * Activate COM and register it:   * Activate COM and register it:
-    * In Project Properties (Alt-Tab) > Application > Assembly Information, check "Make Assembly COM-Visible". Alternatively, In the folder MyLib > Properties > AssemblyInfo, set ''ComVisible'' to true. +    * In Project Properties (Alt-Enter) > Application > Assembly Information, check "Make Assembly COM-Visible". Alternatively, In the folder MyLib > Properties > AssemblyInfo, set ''ComVisible'' to true. 
-    * In Project Properties (Alt-Tab) > Build > Output, and check "Register for COM interop".+    * In Project Properties (Alt-Enter) > Build > Output, and check "Register for COM interop".
     * Build the project. This will register the COM object.     * Build the project. This will register the COM object.
     * Alternatively, manually register COM object:<code>C:\>"%Windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe" /codebase MyLib.dll</code>     * Alternatively, manually register COM object:<code>C:\>"%Windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe" /codebase MyLib.dll</code>
  
 Now the COM object is available to be called by its ''ProgID''. Now the COM object is available to be called by its ''ProgID''.
- 
 == Example == == Example ==
 Example class for COM: Example class for COM: