Search code examples
c#visual-studio-2010comatl

Creating executable COM as ATL project and use it in C#


Trying to create COM object in executable and use it in C# project:

Creating COM in executable.

Create using ATL project enter image description here

enter image description here

Adding class:

enter image description here

enter image description here

Compiles and runs without problem.

Trying to use in C# project and got failure. Self-registration for project... failed. What might be wrong? VS started as admin.

enter image description here


Solution

  • You should add a reference to the type library of the server in your C# project to be able to use it :

    1. Right Click References in the solution explorer and click Add a reference
    2. In references manager choose COM.
    3. Select your type type library ( ComTstLib in your example )
    4. In Solution Explorer, open the shortcut menu for the reference you just added, and then choose Properties.In the Properties window, make sure that the Embed Interop Types property is set to True. This causes Visual Studio to embed type information for COM types in your executables, eliminating the need to deploy primary interop assemblies with your app.

    At deployment time, you just need to ensure that your com server is already installed on the client machine.

    See also msdn