Click here to Skip to main content
15,886,857 members
Articles / Mobile Apps / Windows Mobile

Handling connection notification between a desktop machine and Windows CE based devices

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
14 Jan 2009CPOL4 min read 80.8K   665   53  
This article describes how to get notification when a Windows CE based device is connected or disconnected from a desktop machine.
Public Class Form1
    'This variable is used to store the return value on Advice Register which will
    'be used to deregistr the object.
    Private intAdvaiceReturn As Int32 = 0
    Dim objIDccMan As IDccMan
    'Event handler that are used to register the events on Connetion / DisConnection.
    Private objConnectedEventHandler As EventHandler
    Private objDisConnetedEventHandler As EventHandler

    ''' <summary>
    ''' This button click event is used to register the object of IDccManSink for getting the 
    ''' notification of the Connection / Disconnection.
    ''' </summary>
    ''' <param name="sender">The object of the sender.</param>
    ''' <param name="e">Event arguments</param>
    Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        'To create the object of DccMan class. It is used to get the object of IDccMan
        'becuase we can not create the object of interface directly.
        Dim objDccMan As DccMan = New DccMan()
        'To create the object of IDccMan class.
        objIDccMan = CType(objDccMan, IDccMan)
        'To create the object of DccManSink class. It is used to get the object of IDccManSink
        Dim objDccManSink As DccManSink = New DccManSink()
        'To create the object of IDccManSink
        'Dim objIDccManSink As IDccManSink = CType(objDccManSink, IDccManSink)
        'To initialize the event handlers.
        AddHandler objDccManSink.Active, AddressOf OnConnection
        AddHandler objDccManSink.Disconnect, AddressOf OnDisConnection
        'To register the IDccManSink
        objIDccMan.Advise(objDccManSink, intAdvaiceReturn)
    End Sub
    ''' <summary>
    ''' This button click event is used to unregister the object of IDccManSink so that no event 
    ''' get fired on Connection / Disconnection
    ''' </summary>
    ''' <param name="sender">The object of the sender.</param>
    ''' <param name="e">Event arguments</param>
    Private Sub Deregister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Deregister.Click
        'To unregister the IDccManSink
        objIDccMan.Unadvise(intAdvaiceReturn)
    End Sub
    ''' <summary>
    ''' This method can be used to do some activities which is to be done on Connection.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub OnConnection()
        MsgBox("Connection Established")
    End Sub
    ''' <summary>
    ''' This method can be used to do some activites which is to be done on disconnection.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub OnDisConnection()
        MsgBox("Connection Broken")
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Microsoft India
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions