Important: |
---|
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
4/8/2010
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.
- Instantiate the
IRAPIDesktopinterface using COM's
CoInitializeExmethod.
- Call
IRAPIDesktop::Adviseto register your applications
implementation of the
IRAPISinkinterface. This will alert your application when a
device connects.
- Once a device has connected, call
IRAPIDesktop::EnumDevicesto obtain an instance of the
IRAPIEnumDevicesinterface.
- Call
IRAPIEnumDevices::Nextto obtain an instance of the
IRAPIDeviceinterface. This interface can be used to query
for information about the selected device.
- Call
IRAPIDevice::CreateSessionto establish a session with the
selected device.
- Initialize the underlying communications layer for the session
by calling
IRAPISession::CeRapiInit.
- 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[]) { HRESULT hr = S_OK; // Initialize COM. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); // Create an instance of the IRAPIDesktop interface. IRAPIDesktop *pIRapiDesktop = NULL; hr = CoCreateInstance(CLSID_RAPI, NULL, CLSCTX_INPROC_SERVER, IID_IRAPIDesktop, (void**)&pIRapiDesktop); // Call EnumDevices to obtain an enumeration of connected devices. IRAPIEnumDevices *pIRapiEnumDevices = NULL; if (SUCCEEDED(hr) && pIRapiDesktop) { hr = pIRapiDesktop->EnumDevices(&pIRapiEnumDevices); } // 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) { hr=pIRapiDevice->CreateSession(&pIRapiSession); } if (SUCCEEDED(hr) && pIRapiSession) { // Call CeRapiInit before you call any other IRAPISession methods. hr = pIRapiSession->CeRapiInit(); if (FAILED(hr)) { hr = pIRapiSession->CeRapiGetError(); } else { // Make calls on the session object BOOL bRet = pIRapiSession->CeCheckPassword(TEXT("Password")); if (!bRet) { hr = pIRapiSession->CeRapiGetError(); if(SUCCEEDED(hr)) // If no rapi errors, call CeGetLastError for the error on device { DWORD dwErr = pIRapiSession->CeGetLastError(); } } } } return 0; } |
Note: |
---|
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. |