从C ++所属类外部调用事件或方法 [英] Calling events or methods from outside the owning class in C++

查看:88
本文介绍了从C ++所属类外部调用事件或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VC ++ 2005中做一个ATL项目,用作VB6中的ActiveX.我按照本教程中的步骤添加了方法,属性和事件:编写简单COM/ATL DLL和使用的入门教程. NET [ ^ ] .当我在课堂上工作时,一切都很好.但是现在我需要从全局方法中调用类的事件或方法?

我该怎么办?

谢谢.

解决方案

您想从全局函数中调用哪种语言?

如果您的意思是VB6,则需要在VB6项目中引用新的COM对象,并创建COM对象的实例,如下所示:


  Dim  objA  as   YourATLComObjectName

objA.YourFunction()



如果您的意思是C ++,则需要使用GUID为对象调用:: CoCreateInstance.

确保VB项目可以看到该对象所需的两件事:

1)DLL需要注册,这是在VS编译时默认发生的.在用户计算机上安装它时,请使用regsvr32.
2)DLL需要作为您带入项目的资源之一进行引用.


请使用本文结尾处的论坛,以便作者可以看到它.


blockquote>

使用范围解析运算符(::)访问全局变量


I am doing an ATL Project in VC++ 2005 to use as ActiveX in VB6. I added methods, properties and events following the steps in this tutorial: A Beginner Tutorial for Writing Simple COM/ATL DLL and Using it with .NET [^]. Everything is working fine while I''m working inside the class. But now I need to call an event or method of the class but from a global method?

How can I do this?

Thanks.

解决方案

What language do you want to make the call from a global function?

If you mean VB6, you will need to reference your new COM object in your VB6 project, and create an instance of the COM object like this:


Dim objA as New YourATLComObjectName

objA.YourFunction()



If you mean C++, you will need to call ::CoCreateInstance with the GUID for your object.

The two things you will need in place to make sure your VB project can see the object:

1) The DLL needs to be registered which happens by default when VS compiles it. When you install it on a users machine you use regsvr32.
2) The DLL needs to be referenced as one of the resources that you bring into your project.


Please use the forum at the end of the article so the author can see it.


Use scope resolution operator ( :: ) to access the global variables


这篇关于从C ++所属类外部调用事件或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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