如何在Visual Studio 2008中创建COM DLL? [英] How do you create a COM DLL in Visual Studio 2008?

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

问题描述

自从我写了一个COM DLL以来,已经过去了。我现在做了几个类,继承了一些COM接口,但我想测试它。我知道我必须把一个GUID在某个地方,然后注册它与regsvr32,但涉及的步骤是什么?

It's been ages since I've written a COM dll. I've made a couple of classes now, that inherit from some COM interfaces, but I want to test it out. I know I have to put a GUID somewhere and then register it with regsvr32, but what are the steps involved?

编辑:对不起,忘了提及我使用C + 。

Sorry, forgot to mention I'm using C++.

推荐答案

要创建一个新的ATL COM项目,可以按照下列步骤操作:

To create a new ATL COM project you can proceed as follow:


  1. 文件/新项目

  2. Visual C ++ / ATL / ATL项目

  3. 自定义设置,完成后

您已创建一个新的dll,但它是空的,要添加一个COM对象, p>

You have created a new dll, but it is empty, to add a COM object you can do this:


  1. 项目/添加类

  2. Visual C ++ / ATL / ATL简单对象,
  3. 提供您想要的名称(例如MyObject),然后按完成以添加

一个对象实现一个接口


  1. 在类视图中选择对象类(CMyObject)


  2. 您可以选择要实现的接口
  1. In the class view select the object class (CMyObject)
  2. Right click/Add/Implement Interface...
  3. You can select which Interface will implement

  1. 从您的项目中已有的.idl文件文件

  2. 从嵌入了类型库的.tlb / .dll / .exe

  3. 从已注册的对象


  • 完成后按完成

  • 在不同的文件夹中创建具有相同名称的新ATL项目,并添加您自定义的文件。该向导执行多个任务并创建多个自定义文件。

    PS: It is much easier to create a new ATL project with the same name in a different folder, and add the files you have customized. The wizard does several tasks and create several customized files.

    对于难以按文件添加文件的大型项目,我也这样做,但不是将我的文件添加到新项目中我开始从新项目中复制设置到旧的,添加任何额外的文件,该向导已创建和修复头像stdafx.h合并新的设置。

    For larger projects that are difficult to add file by file, I do the same but instead of adding my files to the new project I start copying the settings from the new projects to the old one, and adding any additional file that the wizard has created and fixing headers like stdafx.h to merge the new settings.

    PPS:如果你想要dll来支持MFC,而不是选择ATL Project,你必须选择MFC / MFC Dll。当您添加ATL简单对象时,向导将要求向项目添加ATL支持。

    PPS: If you want that your dll to support MFC, instead of selecting ATL Project you have to select MFC/MFC Dll. When you add the ATL Simple Object the wizard will ask to add ATL support to the project.

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

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