Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

  1. Create a C# console app project. I name it CSharpApp
  2. 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.
  3. (Removed, kept to keep numbering in answers correct.)
  4. Compile.
  5. 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...'
  6. In Program.cs, Main, create an InteropDemo class and call HelloWorld.
  7. Profit.

Thanks to the answers, I updated the question to reflect the combined solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
246 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try following these steps:

  1. 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.
  2. Open Admin Command Prompt and register your COM DLL: C:WindowsSysWOW64 egsvr32.exe c:full-pathComLib.Interop.dll
  3. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...