3,245
社区成员
发帖
与我相关
我的任务
分享
DWORD dwtext=NOERROR;
HRESULT hr = S_OK;
// Initialize COM.
//hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
clearSession();
addNewInfo(_T("Try to connect a device....."));
CoInitialize(NULL);
// Create an instance of the IRAPIDesktop interface.
hr = CoCreateInstance(CLSID_RAPI,
NULL,
CLSCTX_INPROC_SERVER,
IID_IRAPIDesktop,
(void**)&mpIRapiDesktop);
if (hr ==0 && mpIRapiDesktop)
{
addNewInfo(_T("CoCreateInstance success"));
}else{
addNewInfo(_T("CoCreateInstance failure"));
return ;
}
hr=mpIRapiDesktop->Advise(mpIRapiSink,&dwtext);
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;
}