如何在Visual Studio 2012创建的HelloWorld COM互操作 [英] How to create a HelloWorld COM Interop in Visual Studio 2012

查看:220
本文介绍了如何在Visual Studio 2012创建的HelloWorld COM互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是新来的COM,目前很困惑。我读过关于COM MSDN上和一般网站大量的文档资料,但很多似乎已经过时和过于复杂。

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. 创建一个C#控制台应用程序项目。我将其命名为CSharpApp
  2. 创建一个C ++ ATL项目。我把它叫做ComLib.Interop。
    • 添加类(模板:ATL简单对象),我称之为InteropDemo
    • 在类视图中,右键单击IInteropDemo,并添加一个方法HelloWorld的。
  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.
  • 呼叫regsrv32.exe在编译COM DLL,然后选择DLL中的COM选项卡中的添加引用...

感谢的答案,我更新的问题,以反映综合解决方案。

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

推荐答案

请尝试以下步骤:

  1. 确保这两个项目,非托管C ++和托管C#具有相同的位数,x86或x64。比方说,这是86,为了清晰。
  2. 开启管理命令提示符并注册COM DLL: C:\ WINDOWS \ Syswow64资料\ regsvr32.exe的C:\完整路径\ ComLib.Interop.dll
  3. 运行Visual Studio中的管理。执行步骤1,2,4,5,6。不要做3。
  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:\Windows\SysWOW64\regsvr32.exe c:\full-path\ComLib.Interop.dll
  3. Run Visual Studio as Admin. Do steps 1,2,4,5,6. Don't do 3.

见,如果你到了7。我认为这应该工作。

See if you get to 7. I think that should work.

请注意,你只需要在开发机器上的注册。隔离COM应该在其他地方。

Note you only need the registration on the Development machine. Isolated COM should work everywhere else.

这篇关于如何在Visual Studio 2012创建的HelloWorld COM互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆