passing connection points parameters by ref
-
X| Does anyone know the trick to getting a connection point method to pass parameters by reference? Below is an example of a simple event, which should return a short from the client, but the variant varResult always returns empty?!? Any ideas? IDL: [ uuid(48053E7C-D307-40D2-A380-3B9CB25282AB), version(1.0), helpstring("atl_event 1.0 Type Library") ] library ATL_EVENTLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(224E5ED5-D64E-4556-A785-5ACE0DD8F0B3), helpstring("_IEventTestEvents Interface") ] dispinterface _IEventTestEvents { properties: methods: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); }; [ uuid(840EF1AE-F80F-4F71-9802-03DFE6555B19), helpstring("EventTest Class") ] coclass EventTest { [default] interface IEventTest; [default, source] dispinterface _IEventTestEvents; }; }; C++: template class CProxy_IEventTestEvents : public IConnectionPointImpl { //Warning this class may be recreated by the wizard. public: HRESULT Fire_TestEvent(SHORT * sVar) { CComVariant varResult; T* pT = static_cast(this); int nConnectionIndex; CComVariant* pvars = new CComVariant[1]; int nConnections = m_vec.GetSize(); for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) { pT->Lock(); CComPtr sp = m_vec.GetAt(nConnectionIndex); pT->Unlock(); IDispatch* pDispatch = reinterpret_cast(sp.p); if (pDispatch != NULL) { VariantClear(&varResult); pvars[0] = *sVar; DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); } } delete[] pvars; // *sVar = varResult.iVal; return varResult.scode; } }; __scott
-
X| Does anyone know the trick to getting a connection point method to pass parameters by reference? Below is an example of a simple event, which should return a short from the client, but the variant varResult always returns empty?!? Any ideas? IDL: [ uuid(48053E7C-D307-40D2-A380-3B9CB25282AB), version(1.0), helpstring("atl_event 1.0 Type Library") ] library ATL_EVENTLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(224E5ED5-D64E-4556-A785-5ACE0DD8F0B3), helpstring("_IEventTestEvents Interface") ] dispinterface _IEventTestEvents { properties: methods: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); }; [ uuid(840EF1AE-F80F-4F71-9802-03DFE6555B19), helpstring("EventTest Class") ] coclass EventTest { [default] interface IEventTest; [default, source] dispinterface _IEventTestEvents; }; }; C++: template class CProxy_IEventTestEvents : public IConnectionPointImpl { //Warning this class may be recreated by the wizard. public: HRESULT Fire_TestEvent(SHORT * sVar) { CComVariant varResult; T* pT = static_cast(this); int nConnectionIndex; CComVariant* pvars = new CComVariant[1]; int nConnections = m_vec.GetSize(); for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) { pT->Lock(); CComPtr sp = m_vec.GetAt(nConnectionIndex); pT->Unlock(); IDispatch* pDispatch = reinterpret_cast(sp.p); if (pDispatch != NULL) { VariantClear(&varResult); pvars[0] = *sVar; DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); } } delete[] pvars; // *sVar = varResult.iVal; return varResult.scode; } }; __scott
SPENNER wrote: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); Woops, you can't have out parameters on a connection point event function... If you need a parameter back from the client, you need to implement a callback interface instead of using connection points. - Anders Money talks, but all mine ever says is "Goodbye!"
-
SPENNER wrote: [id(1), helpstring("method TestEvent")] HRESULT TestEvent([in, out] short* sVar ); Woops, you can't have out parameters on a connection point event function... If you need a parameter back from the client, you need to implement a callback interface instead of using connection points. - Anders Money talks, but all mine ever says is "Goodbye!"
That's odd... Because, and I know this isn't the best example, but if I create a quick COM object with VB and define an outgoing interface with a byref parameter, it works great. The resulting IDL is below: [id(0x00000001)] void TestEvent( [in] short eventByVal, [in, out] short* eventAsRef, [in, out] VARIANT_BOOL* eventBoolRef); So, I'm thinking there must be a C++/ATL equivalent, but I can't figure it out...I know I could use a call back interface, but using a connection point would make it more straight forward from the client side... Any idea how to get this to work? __scott
-
That's odd... Because, and I know this isn't the best example, but if I create a quick COM object with VB and define an outgoing interface with a byref parameter, it works great. The resulting IDL is below: [id(0x00000001)] void TestEvent( [in] short eventByVal, [in, out] short* eventAsRef, [in, out] VARIANT_BOOL* eventBoolRef); So, I'm thinking there must be a C++/ATL equivalent, but I can't figure it out...I know I could use a call back interface, but using a connection point would make it more straight forward from the client side... Any idea how to get this to work? __scott
SPENNER wrote: Any idea how to get this to work? Nope, not right now. I have the "Inside ATL" book, but I left it at work... I'll try to see if there's a solution in there... (on monday when I get to work...) - Anders Money talks, but all mine ever says is "Goodbye!"
-
That's odd... Because, and I know this isn't the best example, but if I create a quick COM object with VB and define an outgoing interface with a byref parameter, it works great. The resulting IDL is below: [id(0x00000001)] void TestEvent( [in] short eventByVal, [in, out] short* eventAsRef, [in, out] VARIANT_BOOL* eventBoolRef); So, I'm thinking there must be a C++/ATL equivalent, but I can't figure it out...I know I could use a call back interface, but using a connection point would make it more straight forward from the client side... Any idea how to get this to work? __scott
Are you sure that VB has generated a connnection point and not a custom event handler? Michael :-)
-
Are you sure that VB has generated a connnection point and not a custom event handler? Michael :-)
:confused: That's one of the problems with VB, it's hard to know exactly what's going on. I guess my question should be, how do I create an event function that returns parameters from the client (without using a callback interface)? Anyone have a clue on this one? __scott
-
:confused: That's one of the problems with VB, it's hard to know exactly what's going on. I guess my question should be, how do I create an event function that returns parameters from the client (without using a callback interface)? Anyone have a clue on this one? __scott
Why not just use the callback interface. It's easy to make in VC, and easy to use from VB... - Anders Money talks, but all mine ever says is "Goodbye!"
-
Why not just use the callback interface. It's easy to make in VC, and easy to use from VB... - Anders Money talks, but all mine ever says is "Goodbye!"
One of the good things about using connection points is that the client doesn't need to manage the connection to the incoming interface. That is, to connect to the COM server callback interface, the client must pass a reference of itself to the server. Is there a way for the server to determine if the client is still there before calling the callback function? Is there a way for the server to implicitly connect to the client when the client instantiates an object from the server? I'm not sure that made sense...oh well __scott
-
One of the good things about using connection points is that the client doesn't need to manage the connection to the incoming interface. That is, to connect to the COM server callback interface, the client must pass a reference of itself to the server. Is there a way for the server to determine if the client is still there before calling the callback function? Is there a way for the server to implicitly connect to the client when the client instantiates an object from the server? I'm not sure that made sense...oh well __scott
SPENNER wrote: I'm not sure that made sense...oh well I know exactly what you mean. I just don't know of a solution... - Anders Money talks, but all mine ever says is "Goodbye!"