c++ - 从 VS2012 在 C++ 中使用 ATL 创建 COM

标签 c++ visual-studio-2012 com

尝试在 Visual Studio 2012 中使用 ATL 创建简单的 COM 库。 我这样做:

 New ATL Project
 Welcome to the ATL Project Wizard
 Next
 Application Settings - no change (DLL)
 Next
 Finish

enter image description here

得到了很多文件:

enter image description here

试图了解在何处添加可由 COM 用户调用的简单函数。我发现只有一个地方可以使用向导添加功能:

enter image description here

但我发现在参数选择方面缺少一些东西,比如 in、out、retval。 enter image description here

我希望在添加新功能后至少 IDL 文件也会更新,但这并没有发生。

从 VS2012 的 Visual C++ 使用 ATL 创建简单的 COM 类的方法是什么?

最佳答案

  1. 添加一个新类 enter image description here

  2. 填写字段 enter image description here enter image description here

在这一步 SomeObject.h 之后,将创建 SomeObject.cpp 文件并将其添加到您的解决方案中,ISomeObject 接口(interface)声明将是添加到 .idl 文件。

  1. 转到类 View (默认组合 ctrl+shift+C),选择 ISomeObject,添加一个新方法 enter image description here

  2. 填写字段 enter image description here

在这一步之后,someMethod 将被添加到 .idl 文件、.h 文件和 .cpp文件。您所要做的就是在 .cpp 文件中编写 someMethod 的实现。

关于c++ - 从 VS2012 在 C++ 中使用 ATL 创建 COM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33211156/

相关文章:

vba - 无法将字符串从 VBA (Excel) 传递到我的 COM 对象

c++ - 调用 C# COM 对象后从 C++ 中的 HRESULT 检索错误消息

c# - Javascript Com 数组组件给我错误的数组值

没有虚函数的 C++ 接口(interface)

c++ - 为什么 C++ 中的 "this"指针是指针而不是引用?

opengl - 设置 OpenGL : Why am I getting these errors? 为什么 Visual Studio 卡住?

debugging - Visual Studio 不会因用户未处理的异常而中断

c++ - rand() 有某种数值限制吗?

c++ - jpegtran.exe 无法正确旋转图像

c# - MS Visual Studio 2012 Ultimate - 调试器 .NET 版本