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.
Try following these steps:
- Make sure both projects, unmanaged C++ and managed C# have the same bitness, either x86 or x64. Let's say it's x86, for clarity.
- Open Admin Command Prompt and register your COM DLL:
C:\Windows\SysWOW64\regsvr32.exe c:\full-path\ComLib.Interop.dll
- Run Visual Studio as Admin. Do steps 1,2,4,5,6. Don't do 3.
See if you get to 7. I think that should work.
Note you only need the registration on the Development machine. Isolated COM should work everywhere else.