We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,254 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Calling events or methods from outside the owning class in C++

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: http://www.codeproject.com/KB/atl/SimpleATLComWithDotNet.aspx. 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.

I already tried to query an interface, but the event is not dispatched; maybe I'm not doing it well.

How can I do this?

Thanks

2
Contributors
2
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
3
Views
luisborlido
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

The problem is just the came as in any other c++ program -- the global method must have an instance of the c++ class in order to call one of its methods, unless the c++ class method has been declared as static.

class foo
{
public:
   static int static_method() { return 0; }
   int another_method();
}

void gmethod()
{
   foo par;
   foo::static_method(); // call a static method

   par.another_method(); // call a non-static method
}
Ancient Dragon
Achieved Level 70
Team Colleague
32,140 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,576
Skill Endorsements: 69

Thanks for your reply.

But the methods are not static and when I try:

CEngine engine;
engine.Fire_SetupError(100);

...I get the following errors:

.\Engine.cpp(966) : error C2259: 'CEngine' : cannot instantiate abstract class 
        due to following members:
        'HRESULT CEngine::QueryInterface(const IID &,void **) throw()' : is abstract
        d:\projects\visualstudio\2005\facerecognition\facerecognition\Engine.h(91) : see declaration of 'CEngine::QueryInterface'
        ...

I also tried:

CEngine engine;
hr = CoCreateInstance(CLSID_Engine, NULL, CLSCTX_INPROC_SERVER, IID_IEngine, (void **) & engine);
if(SUCCEEDED(hr)) {

	engine->Fire_SetupError(100);		

}

This compiles just fine, but when I run the client application, it gives me an exception. I also tried with IID_IDispatch and IID_ConnectionPointContainer, but no luck.

Do you have other hint?

luisborlido
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0642 seconds using 2.75MB