Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:creating_com_library [2012/05/14 15:45] 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 = | ||
- | Source: [[http:// | + | |
- | + | | |
- | | + | |
- | * Open a Class Library project (Eg: MyProject). | + | * Add a new interface |
- | * Add a new interface | + | { |
- | * Add a using '' | + | void launch(); |
- | * Add the attributes '' | + | }</ |
- | * You can generate | + | |
- | * Add a class that implement the interface. | + | [InterfaceType(ComInterfaceType.InterfaceIsDual)] |
- | * Add the attributes '' | + | [Guid(" |
- | * '' | + | |
- | * Under the prperties | + | |
- | * In the project properties menu, in the build tab mark " | + | public class MyLauncher: IMyLauncher |
- | * Build the project. | + | { |
+ | public void launch() | ||
+ | { | ||
+ | } | ||
+ | }</ | ||
+ | | ||
+ | [ClassInterface(ClassInterfaceType.None)] | ||
+ | [Guid(" | ||
+ | [ProgId(" | ||
+ | | ||
+ | * Activate COM and register it: | ||
+ | * In Project Properties (Alt-Enter) > Application > Assembly Information, | ||
+ | * In Project Properties (Alt-Enter) > Build > Output, and check " | ||
+ | * Build the project. | ||
+ | * Alternatively, | ||
Now the COM object is available to be called by its '' | Now the COM object is available to be called by its '' | ||
+ | == Example == | ||
Example class for COM: | Example class for COM: | ||
<code csharp> | <code csharp> | ||
Line 27: | Line 41: | ||
using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||
- | namespace | + | namespace |
{ | { | ||
Line 36: | Line 50: | ||
} | } | ||
- | [ClassInterface(ClassInterfaceType.None), | + | [ClassInterface(ClassInterfaceType.None), |
public class MyLauncher: IMyLauncher | public class MyLauncher: IMyLauncher | ||
{ | { | ||
Line 53: | Line 67: | ||
Example how to call COM object using VB script: | Example how to call COM object using VB script: | ||
<code vb> | <code vb> | ||
- | set obj = createObject(" | + | set obj = createObject(" |
</ | </ | ||
Line 60: | Line 74: | ||
Hello, World, from a COM object | Hello, World, from a COM object | ||
</ | </ | ||
+ | |||
+ | == References == | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// |