Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 14 Jan 2009
This article describes how to get notification when a Windows CE based device is connected or disconnected from a desktop machine.
GetNotificationOnConnect_src.zip
GetNotificationOnConnect
WindowsApplication1
bin
Release
WindowsApplication1.exe
WindowsApplication1.vshost.exe
GetNotificationOnConnect.vbproj.user
My Project
Application.myapp
Settings.settings
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)

Share

About the Author

Anil_gupta
Software Developer Microsoft India
India India
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 15 Jan 2009
Article Copyright 2006 by Anil_gupta
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid