Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following code examples demonstrate how to handle Buddy Group events. The operations in the Initialize RTC and Create a Buddy Group and Add Buddies code examples must be performed before using this example.
Note This example does not contain error checking or releases appropriate for real code.
C++ Code Example 1: Event Sink
// The event sink to attach to the event HRESULT Event(RTC_EVENT RTCEvent, IDispatch* pEvent) { // The RTC event sink of events shown in the example switch(RTCEvent) { case RTCE_GROUP: HandleGroupEvents(pEvent); break; // Add handlers for other events. } return S_OK; }
C++ Code Example 2: Event Handler
HRESULT HandleGroupEvents(IDispatch *pEvent) { HRESULT hr = S_OK; LONG lStatusCode = S_OK; IRTCBuddyGroupEvent * pGE; RTC_GROUP_EVENT_TYPE enEventType; hr = pEvent->QueryInterface(IID_IRTCBuddyGroupEvent, (LPVOID *)&pGE); // If (hr != S_OK), process the error here. hr = pGE->get_EventType(&enEventType); // If (hr != S_OK), process the error here. hr = pGE->get_StatusCode(&lStatusCode); // If (hr != S_OK), process the error here. // Check the status code: if (FAILED(lStatusCode)) { // If the status code is a failure HRESULT, this // signifies that the operation did not complete // successfully. Handle failures here. } // Process the event based on its type. switch (enEventType) { case RTCGET_GROUP_ADD: // The group has been added successfully. // Update the user interface by // displaying the group. break; case RTCGET_GROUP_REMOVE: // The group has been removed successfully. // Update the user interface by removing // the group. break; case RTCGET_GROUP_UPDATE: // The group has been modified successfully. break; case RTCGET_GROUP_BUDDY_ADD: // A buddy has been successfully added to // the group. Update the user interface // by displaying the buddy as part of the group. break; case RTCGET_GROUP_BUDDY_REMOVE: // A buddy has been successfully removed from // the group. Update the user interface // by removing the buddy from the group. break; case RTCGET_GROUP_ROAMED: // There is a successful transition from a // nonroaming state to a roaming state. // This will happen only if you add groups and // buddies to the groups before you begin roaming. break; } return hr; }
Visual Basic Example: Event Handler
' In Event Handler, process the event based on its type. Dim pEvent As IRTCBuddyGroupEvent ' Add code here to retrieve the event as pEvent. lEventType = pEvent.EventType select Case enEventType case RTCGET_GROUP_ADD: ' The group has been added successfully. ' Update the user interface by displaying ' the group. case RTCGET_GROUP_REMOVE: ' The group has been removed successfully. ' Update the user interface by removing ' the group. case RTCGET_GROUP_UPDATE: ' The group has been modified successfully. case RTCGET_GROUP_BUDDY_ADD: ' A buddy has been successfully added to the group. ' Update the user interface by displaying ' the buddy as part of the group. case RTCGET_GROUP_BUDDY_REMOVE: ' A buddy has been successfully removed from the ' group. Update the user interface by removing ' the buddy from the group. case RTCGET_GROUP_ROAMED: ' There is a successful transition from ' a nonroaming state to a roaming state. ' This will happen only if you add groups and ' buddies to the groups before you begin roaming. end select