AIMCC C# Plugin Tutorial


Lesson 3 : Sinking AIMCC Events

Your plugin now can load into AIMCC, and from there can call methods on AIMCC objects. But it cannot receive events from AIMCC, such as when a buddy comes online or when a message arrives. To do this, your plugin needs to add event handlers for the DAccEvents events that you want to receive.

First we will add a variable to the session to store the IAccSession object. We do this by adding the following lines of code:

. . .       
         
public void Init(AccSession session, IAccPluginInfo pluginInfo)
          {
              m_session = session;
          }

          public void Shutdown()
          {
              m_session = null;
          }          
. . .

          private AccSession m_session;
    }
}

Next, we add code to Init to add event handlers for the events we want to receive. In this case we will add an event handler for OnStateChange.

. . .      

          public void Init(AccSession session, IAccPluginInfo pluginInfo)
          {
              m_session = session;
              m_session.OnStateChange += new DAccEvents_OnStateChangeEventHandler(m_session_OnStateChange);
          }

. . .      

          private void m_session_OnStateChange(AccSession piSession, AccSessionState State, AccResult hr)
          {
          }

. . .

One of the nice things about Visual Studio .NET 2003 is that once you type +=, it will add the rest of the code with two presses of the TAB key.

That's all there is to it! If you now rebuild your plugin, your OnStateChange function will be called whenever the session state changes in AIMCC.

Next Lesson | Back to Table of Contents


Questions? Visit http://developer.aim.com/
Last updated: 03/17/2007