First off, I am new to COM, and currently quite confused. I've read a lot of documentation on COM on MSDN and the general web, but a lot of it seems outdated and overly complex.
Here's what I believe to be necessary to get it to work. It doesn't yet, so I am sure I am missing something, but by giving my recipe, I hope someone can spot the problem:
- Create a C# console app project. I name it CSharpApp
- Create a C++ ATL project. I call it ComLib.Interop.
- Add class (template: ATL Simple Object), which I call "InteropDemo"
- In class view, right-click IInteropDemo and add a method HelloWorld.
- (Removed, kept to keep numbering in answers correct.)
- Compile.
- Add reference to ComLib.Interop.dll to CSharpApp.
- Call regsrv32.exe on the compiled COM dll, then select the DLL in the COM tab in 'Add references...'
- In Program.cs, Main, create an InteropDemo class and call HelloWorld.
- Profit.
Thanks to the answers, I updated the question to reflect the combined solution.
See Question&Answers more detail:os