How to use Advise to subscribe to COM events

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I currently have the following code<br/>
<pre class="prettyprint HRESULT hr = CoInitialize(NULL); 
ISTIEventsPtr evnt(__uuidof(STIEvents));   
IConnectionPointContainer *point_container;  
IConnectionPoint *conn_point;       
HRESULT qint = evnt-&gt;QueryInterface(IID_IConnectionPointContainer,(void**)&amp;point_container);  
HRESULT qpoint = point_container-&gt;FindConnectionPoint(__uuidof(_ISTIEventsEvents),&amp;conn_point);[/code]
<br/>
Now that I have a conn_point how do I subscribe to an event ? I know I would have to use the advise method but I am totally confused with the parameter. There are tons of events available but I only want to use one.Here is a snapshot from the tlb file.<br/>
<br/>
    [<br/>
      uuid(18A8B57B-D223-4796-9948-E2426ED7C9E7),<br/>
      helpstring(&quot;ISTIEvents Interface&quot;),<br/>
      dual<br/>
    ]<br/>
    dispinterface ISTIEvents {<br/>
        properties:<br/>
        methods:<br/>
            [id(0x00000001), helpstring(&quot;method SetOrderEventsAsStructs&quot;)]<br/>
            void SetOrderEventsAsStructs([in] VARIANT_BOOL bStruct);<br/>
            [id(0x00000002), helpstring(&quot;method GetQueueCount&quot;)]<br/>
            long GetQueueCount();<br/>
            [id(0x00000003), helpstring(&quot;method Destroy&quot;)]<br/>
            void Destroy();<br/>
    };<br/>
<br/>
and the events are as follows<br/>
<br/>
    [<br/>
      uuid(192B9F3E-DF39-41A5-95E0-0333B061CAB8),<br/>
      helpstring(&quot;_ISTIEventsEvents Interface&quot;)<br/>
    ]<br/>
    dispinterface _ISTIEventsEvents {<br/>
        properties:<br/>
        methods:<br/>
            [id(0x00000001), helpstring(&quot;method OnSTITradeUpdateMsg&quot;)]<br/>
            void OnSTITradeUpdateMsg([in] ISTITradeUpdateMsg* oSTITradeUpdateMsg);<br/>
            [id(0x00000002), helpstring(&quot;method OnSTIOrderUpdateMsg&quot;)]<br/>
            void OnSTIOrderUpdateMsg([in] ISTIOrderUpdateMsg* oSTIOrderUpdateMsg);<br/>
            [id(0x00000003), helpstring(&quot;method OnSTIOrderRejectMsg&quot;)]<br/>
            void OnSTIOrderRejectMsg([in] ISTIOrderRejectMsg* oSTIOrderRejectMsg);<br/>
            [id(0x00000004), helpstring(&quot;method OnSTIOrderConfirmMsg&quot;)]<br/>
            void OnSTIOrderConfirmMsg([in] ISTIOrderConfirmMsg* oSTIOrderConfirmMsg);<br/>
            [id(0x00000005), helpstring(&quot;method OnSTITradeUpdate&quot;)]<br/>
            void OnSTITradeUpdate([in] structSTITradeUpdate* structTradeUpdate);<br/>
            [id(0x00000006), helpstring(&quot;method OnSTIOrderUpdate&quot;)]<br/>
            void OnSTIOrderUpdate([in] structSTIOrderUpdate* structOrderUpdate);<br/>
            [id(0x00000007), helpstring(&quot;method OnSTIOrderReject&quot;)]<br/>
            void OnSTIOrderReject([in] structSTIOrderReject* structOrderReject);<br/>
            [id(0x00000008), helpstring(&quot;method OnSTIOrderConfirm&quot;)]<br/>
            void OnSTIOrderConfirm([in] structSTIOrderConfirm* structOrderConfirm);<br/>
            [id(0x00000009), helpstring(&quot;method OnSTIShutdownStruct&quot;)]<br/>
            HRESULT OnSTIShutdown();<br/>
            [id(0x0000000a), helpstring(&quot;method OnSTILinkSymChange&quot;)]<br/>
            void OnSTILinkSymChange([in] structSTILink* structLink);<br/>
            [id(0x0000000b), helpstring(&quot;method OnSTIDrop&quot;)]<br/>
            void OnSTIDrop([in] structSTIDrop* structDrop);<br/>
            [id(0x0000000c), helpstring(&quot;method OnSTITradeUpdateXML&quot;)]<br/>
            HRESULT OnSTITradeUpdateXML([in] BSTR* bstrTrade);<br/>
            [id(0x0000000d), helpstring(&quot;method OnSTIOrderUpdateXML&quot;)]<br/>
            HRESULT OnSTIOrderUpdateXML([in] BSTR* bstrOrder);<br/>
            [id(0x0000000e), helpstring(&quot;method OnSTIOrderRejectXML&quot;)]<br/>
            HRESULT OnSTIOrderRejectXML([in] BSTR* bstrOrder);<br/>
            [id(0x0000000f), helpstring(&quot;method OnSTIOrderConfirmXML&quot;)]<br/>
            HRESULT OnSTIOrderConfirmXML([in] BSTR* bstrOrder);<br/>
    };<br/>
<br/>
I only want to use the last event which is<br/>
<br/>
    HRESULT OnSTIOrderConfirmXML([in] BSTR* bstrOrder);<br/>
<br/>
is it possible to use only one event and ignore the others ? and how would I subscribe to it ? Any suggestions would be appreciated<br/>
<br/>
 <br/>
<
A candle loses nothing by lighting another candle.

View the full article
 
Back
Top