Exemple

//------------------------------------------------------------------- // ECLStartNotify class // // This sample demonstrates the use of: // // ECLStartNotify::NotifyEvent // ECLStartNotify::NotifyError // ECLStartNotify::NotifyStop // ECLConnMgr::RegisterStartEvent // ECLConnMgr::UnregisterStartEvent //------------------------------------------------------------------- //................................................................... // Define a class derived from ECLStartNotify //................................................................... class MyStartNotify: public ECLStartNotify { public: // Define my own constructor to store instance data MyStartNotify(HANDLE DataHandle); // We have to implement this function void NotifyEvent(ECLConnMgr *CMObj, long ConnHandle, BOOL Started); // We will take the default behaviour for these so we // don't implement them in our class: // void NotifyError (ECLConnMgr *CMObj, long ConnHandle, ECLErr ErrObject); // void NotifyStop (ECLConnMgr *CMObj, int Reason); 
private: // We will store our application data handle here HANDLE MyDataH; }; //................................................................... MyStartNotify::MyStartNotify(HANDLE DataHandle) // Constructor //................................................................... { MyDataH = DataHandle; // Save data handle for later use } //................................................................... void MyStartNotify::NotifyEvent(ECLConnMgr *CMObj, long ConnHandle, BOOL Started) //................................................................... { // This function is called whenever a connection start or stops. if (Started) printf("Connection %c started.\n", CMObj->ConvertHandle2ShortName(ConnHandle)); else printf("Connection %c stopped.\n", CMObj->ConvertHandle2ShortName(ConnHandle)); return; } //................................................................... // Create the class and begin start/stop monitoring. //................................................................... void Sample75() { ECLConnMgr CMgr; // Connection manager object MyStartNotify *Event; // Ptr to my event handling object HANDLE InstData; // Handle to application data block (for example) try { Event = new MyStartNotify(InstData); // Create event handler CMgr.RegisterStartEvent(Event); // Register to get events 
 // At this point, any connection start/stops will cause the // MyStartEvent::NotifyEvent() function to execute. For // this sample, we put this thread to sleep during this // time. printf("Monitoring connection start/stops for 60 seconds...\n"); Sleep(60000); // Now stop event generation. CMgr.UnregisterStartEvent(Event); printf("Start/stop monitoring ended.\n"); delete Event; // Don't delete until after unregister! } catch (ECLErr Err) { printf("ECL Error: %s\n", Err.GetMsgText()); } } // end sample