The Windows Portable Devices (WPD) SDK includes two sample command-line applications written in C++. The first application, WpdApiSample, lets the user accomplish tasks like: enumerating connected devices, exploring objects on these devices, and enumerating object properties. The second application, WpdServiceApiSample, is designed to explore a Contacts Device Service. The user can enumerate connected device services, retrieve properties and formats for a given service, and invoke methods on that service. The WPD SDK is included in the Windows SDK which can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en

The following sections describe each sample application, the modules found in that application, and the operating systems that it will run on.

WpdApiSample

Of the two sample applications, the WpdApiSample, is the most generalized. It demonstrates how a developer would use the WPD API to accomplish tasks common to most applications. For example, this application demonstrates how a developer would:

· Enumerate the devices connected to a computer.

· Establish a connection to a connected device.

· Enumerate device content.

· Retrieve the properties for a given object on a device.

· Set the properties for a given object on a device.

· Retrieve general device information (for example, a description of the operations that a device can perform).

· Operate on device content (for example, move a file from one folder on the device to another).

The WpdApiSample application includes the following files:

File

Description

ContentEnumeration.cpp

Contains functions that enumerate all the objects on a device.

ContentProperties.cpp

Contains functions that read and write object properties and make bulk property set/get requests.

ContentTransfer.cpp

Contains functions that transfer content to or from the device, read object type requirements, and create a folder on the device.

DeviceCapabilities.cpp

Contains functions to list the functional object types on the device, list the content types supported by each functional object type, and display rendering object profiles.

DeviceEnumeration.cpp

Lists the friendly names, manufacturers, and descriptions of all connected devices.

DeviceEvents.cpp

Contains functions that log device events and their parameters whenever events are fired.

Stdafx.cpp

Includes the standard files.

WpdApiSample.cpp

Displays a list of available devices and tasks available to the user.

This application is supported on Windows XP, Windows Vista, and Windows 7.

Even if you have no WPD devices connected to your computer, you can familiarize yourself with the WPD API and this application by installing the WpdHelloWorldDriver sample from the Windows Driver Kit (WDK), which emulates a simple WPD device. For information about downloading the WDK, see http://www.microsoft.com/whdc/resources/downloads.mspx

WpdServiceApiSample

The WpdServiceApiSample sample demonstrates how a developer would use the WPD API to explore a Contacts Device Service on a device that’s attached to a computer. For example, this application demonstrates how a developer would:

· Enumerate the services on a devce.

· Open a service.

· Enumerate service content.

· Retrieve the events and methods supported by a service.

· Access the service object properties.

· Invoke service methods (both synchronously and asynchronously).

The WpdServiceApiSample application includes the following files:

File

Description

ContentEnumeration.cpp

Contains methods that enumerate the content on a given Contacts service.

ContentProperties.cpp

Contains methods that read and write properties on a given Contacts service.

ServiceCapabilities.cpp

Contains the methods that retrieve the supported formats, events, and abstract services that are supported by a given Contacts service.

ServiceEnumeration.cpp

Contains the helper functions that retrieve device information such as the device-friendly name or the supported Contacts services.

ServiceMethods.cpp

Contains the methods that retrieve and invoke methods supported by a given Contacts service.

Stdafx.cpp

Includes the standard files.

WpdServiceApiSample.cpp

Displays a list of available device services and tasks available to the user

Because Device Services is new for Windows 7, this application is only supported in the Windows 7 operating system.

Even if you have no WPD devices connected to your computer, you can familiarize yourself with the WPD API and this application by installing the WpdServiceSampleDriver that’s included as a sample in the Windows Driver Kit (WDK). This sample driver emulates a simple WPD device service.

Other Samples

In addition to the two samples that ship in the SDK, the WPD team created three other samples that demonstrate using WPD to display the current office temperature in the Windows Sidebar. One of these samples is written using unmanaged-code and C++; another is written using the COM interop and Visual Basic .Net; and, the third is written using the COM interop and Visual C# .Net.

All three of these samples rely on a simple temperature sensor device, device-firmware, and a sample WPD driver. You can download the circuit description, device-firmware, and sample driver from here: http://www.microsoft.com/whdc/device/media/WPD_drv.mspx

Once you build the device, download the firmware, and install the driver, you can begin exploring the WPD API samples. You’ll find a description of the unmanaged application at: http://blogs.msdn.com/wpdblog/archive/2007/12/19/creating-a-temperature-sensor-gadget-for-windows-sidebar-with-c.aspx.

You’ll find a description of the COM interop and Visual Basic .Net application at: http://wpdtempsensor.codeplex.com/.

And, you’ll find a description of the COM interop and the C# application at: http://blogs.msdn.com/wpdblog/archive/2007/11/26/creating-a-temperature-sensor-gadget-for-windows-sidebar.aspx.

This posting is provided "AS IS" with no warranties and confers no rights.