events in non-visual activex controls 
Author Message
 events in non-visual activex controls

I have a question regarding connection points and activex controls. How do I
connect to the events of  non-visual activex control? I'm hosting the
control in a dialog, but as it is a not a visual control, theres no
CAxWindow member and no CreateControl. effetively I have no child window ID.
I'm using a simple dialog and the IDispEventImpl<> template but what is the
sink?  how do I connect ot the control's events?
Thanks in advance.


Fri, 13 Feb 2004 23:52:43 GMT  
 events in non-visual activex controls
Hi,

The below code snippet illustrates a general method to use a sink object,
For clarity I have omitted those error handling codes. Hope it can be
helpful to you:

//create a sink class
class CEventHandler: public IDispEventImpl<0,
        CEventHandler,
        &DIID__IaconnectionEvents,
        &LIBID_TESTCONNECTIONLib,
        1,
        0>
{
public:
        void _stdcall e1(double a);
BEGIN_SINK_MAP(CEventHandler)
        SINK_ENTRY_EX(0, DIID__IaconnectionEvents, 1, e1)
END_SINK_MAP()

Quote:
};

void __stdcall CEventHandler::e1(double a)
{
.........

Quote:
}

//create a sink object and call advise
CComPtr<Iaconnection> pt;   // this is your control object or something else
HRESULT hr = CoCreateInstance(CLSID_aconnection,NULL, CLSCTX_ALL,
IID_Iaconnection, (void **) &pt);
CEventHandler *pEv = new CEventHandler;
pEv->DispEventAdvise(pt);
........................
pEv->DispEventUnadvise(pt);
delete pEv;

For more information, please consult MSDN about IConnectionPoint,
IConnectionPointContainer, and Sink.

Thanks,
Freist



Sat, 14 Feb 2004 12:21:52 GMT  
 events in non-visual activex controls
this whole thing is fishy...:-) hooking up events from a VB
activex control in a VC app...I have done it so many times for VC visible
controls, VB visible controls, but for this VB non-visual control..it's got
me stumped..LOL.
it's worse cause I think I'm doing everything correctly. I mean, it's not
rocket science,right? The the DispEventImpl<> template has worked for me
everytime...but this.

First I tried to hookup IDispEventImpl<> in my dislog class...didn't work
tried directly using IDispEventSimpleImpl<>...didn't work, though it's
essentially the same
then I tried to create a separate sink class CEventHandler, where I hooked
up IDispEventImpl<> and called DispEventAdvise() through instance pointer as
suggested by Friest at this ng...didn't work
tried directly querying for IConnectionPointContainer and IConnectionPoint
and then Advise() in the raw...didn't work.

Then  chucked out everything and used CAxWindow to host control through
Create() and QueryControl() to get sink and call AtlAdviseSinkMap() or
DispEventAdvise()...but still it didn't work.

And all the time I'm getting 2/3 first chance exception in
msvbvm6.dll,though I know it's nothing to get worried and is happenning at a
much lower level...right?

Am I fundamentally doing something wrong? I'm simply #importing server's
typelib and using generated smart pointers to instantiate and use component.
I can access every method and use functionality... except the events handler
part . even discarded smart pointers and tried raw CoCreateInstance() etc,
if only for the luck factor..

when I try mapping event handlers in an MFC client using class wrappers
generated by the wizard, it works. so I know there's nothing wrong with the
ocx/dll. Is this a cross apartment call problem? do I need to marshal
interfaces or something? I need to get it working urgently and am running
out of options...


Quote:
> Hi,

> The below code snippet illustrates a general method to use a sink object,
> For clarity I have omitted those error handling codes. Hope it can be
> helpful to you:

> //create a sink class
> class CEventHandler: public IDispEventImpl<0,
> CEventHandler,
> &DIID__IaconnectionEvents,
> &LIBID_TESTCONNECTIONLib,
> 1,
> 0>
> {
> public:
> void _stdcall e1(double a);
> BEGIN_SINK_MAP(CEventHandler)
> SINK_ENTRY_EX(0, DIID__IaconnectionEvents, 1, e1)
> END_SINK_MAP()
> };
> void __stdcall CEventHandler::e1(double a)
> {
> .........
> }

> //create a sink object and call advise
> CComPtr<Iaconnection> pt;   // this is your control object or something
else
> HRESULT hr = CoCreateInstance(CLSID_aconnection,NULL, CLSCTX_ALL,
> IID_Iaconnection, (void **) &pt);
> CEventHandler *pEv = new CEventHandler;
> pEv->DispEventAdvise(pt);
> ........................
> pEv->DispEventUnadvise(pt);
> delete pEv;

> For more information, please consult MSDN about IConnectionPoint,
> IConnectionPointContainer, and Sink.

> Thanks,
> Freist



Sun, 15 Feb 2004 06:05:06 GMT  
 events in non-visual activex controls
ah ha! the obvious is often very hard to see. the problem here was that the
event handler expects a long parameter. So what I neede to do was use
_ATL_FUNC_INFO OnEpochEvent = {CC_STDCALL, VT_EMPTY,1,(VT_I4)}; to define
handler params and use SINK_ENTRY_INFO() and everything was working...
again, the obvious is often hard to see....
thanks for everything, guys.
this NG rocks!


Quote:
> Hi,

> The below code snippet illustrates a general method to use a sink object,
> For clarity I have omitted those error handling codes. Hope it can be
> helpful to you:

> //create a sink class
> class CEventHandler: public IDispEventImpl<0,
> CEventHandler,
> &DIID__IaconnectionEvents,
> &LIBID_TESTCONNECTIONLib,
> 1,
> 0>
> {
> public:
> void _stdcall e1(double a);
> BEGIN_SINK_MAP(CEventHandler)
> SINK_ENTRY_EX(0, DIID__IaconnectionEvents, 1, e1)
> END_SINK_MAP()
> };
> void __stdcall CEventHandler::e1(double a)
> {
> .........
> }

> //create a sink object and call advise
> CComPtr<Iaconnection> pt;   // this is your control object or something
else
> HRESULT hr = CoCreateInstance(CLSID_aconnection,NULL, CLSCTX_ALL,
> IID_Iaconnection, (void **) &pt);
> CEventHandler *pEv = new CEventHandler;
> pEv->DispEventAdvise(pt);
> ........................
> pEv->DispEventUnadvise(pt);
> delete pEv;

> For more information, please consult MSDN about IConnectionPoint,
> IConnectionPointContainer, and Sink.

> Thanks,
> Freist



Sun, 15 Feb 2004 10:04:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Q: ActiveX Control on a NON-Dlg how do I get Events

2. Events in non-visual controls

3. Handling ActiveX control events without an ActiveX container

4. Controlling an event of an ActiveX control

5. Handling Events from a Visual Basic ActiveX EXE

6. How to fire Event in OLE control from non member function

7. Non-rectangular ActiveX controls

8. Adding non-ActiveX controls to ClassWizard

9. Howto? Non window container for ActiveX control

10. Pass non-void values into constructor of ActiveX control

11. ListView: Using ActiveX control with non-trivial interface

12. Adding non-ActiveX controls to ClassWizard

 

 
Powered by phpBB® Forum Software