1,105,380 Community Members

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

Member Avatar
luisborlido
Newbie Poster
2 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Ancient Dragon
Achieved Level 70
27,637 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
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
}
Member Avatar
luisborlido
Newbie Poster
2 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: