This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for

The IRAPISessioninterface provides the methods that perform operations on the remote Windows Embedded CE-based device. This set of methods is essentially the same as the functions provided by the original RAPI library.

The IRAPISinkinterface should be implemented by RAPI2 applications in order to receive notifications from the connection manager when remote devices connect and disconnect.

The IRAPIDesktop, IRAPIEnumDevices, and IRAPIDeviceinterfaces are used to discover, query, and create a session with a connected device.

Use the following steps to initialize RAPI2 and create a session with a connected device.

  1. Instantiate the IRAPIDesktopinterface using COM's CoInitializeExmethod.

  2. Call IRAPIDesktop::Adviseto register your applications implementation of the IRAPISinkinterface. This will alert your application when a device connects.

  3. Once a device has connected, call IRAPIDesktop::EnumDevicesto obtain an instance of the IRAPIEnumDevicesinterface.

  4. Call IRAPIEnumDevices::Nextto obtain an instance of the IRAPIDeviceinterface. This interface can be used to query for information about the selected device.

  5. Call IRAPIDevice::CreateSessionto establish a session with the selected device.

  6. Initialize the underlying communications layer for the session by calling IRAPISession::CeRapiInit.

  7. Call methods of the IRAPISessioninterface to perform operations on the connected device.

Code Example

The following code example illustrates the initialization of the RAPI2 interfaces.

Copy Code
int _tmain(int argc, _TCHAR* argv[])

	// Initialize COM.

	// Create an instance of the IRAPIDesktop interface.
	IRAPIDesktop *pIRapiDesktop = NULL;
	hr = CoCreateInstance(CLSID_RAPI,

	// Call EnumDevices to obtain an enumeration of connected
	IRAPIEnumDevices *pIRapiEnumDevices = NULL;
	if (SUCCEEDED(hr) && pIRapiDesktop)
			hr =

	// Call Next to get an interface to the device.
	IRAPIDevice *pIRapiDevice = NULL;
	if (SUCCEEDED(hr) && pIRapiEnumDevices)
			hr = pIRapiEnumDevices->Next(&pIRapiDevice);

	// Call CreateSession to establish a session with the
connected device.
	IRAPISession *pIRapiSession = NULL;
	if (SUCCEEDED(hr) && pIRapiDevice)

	if (SUCCEEDED(hr) && pIRapiSession)
			// Call CeRapiInit before you call any other
IRAPISession methods.
			hr = pIRapiSession->CeRapiInit();
			if (FAILED(hr))
				hr = pIRapiSession->CeRapiGetError();
				// Make calls on the session object 
				BOOL bRet =

				if (!bRet)
						hr = pIRapiSession->CeRapiGetError();
						if(SUCCEEDED(hr)) // If no rapi errors,
call CeGetLastError for the error on device
							DWORD dwErr =

	return 0;

When initializing the RAPI2 interfaces in a multi-threaded application, be mindful of the access restriction between apartments. If the RAPI2 interfaces are initialized in an STA thread, they will not be accessible from other apartments.

See Also

Other Resources

RAPI2 Reference