ee-user
asked on
Detect PPC before CeRapiInit hangs
I want to detect whether the desktop computer has a Pocket-PC connected. I've used CeRapiInit(), but it hangs indefinitely if a PPC isn't attached.
The eVC 3.0 documentation indicates:
"A call to CeRapiInit does not return until the connection is made, an error occurs, or another thread calls CeRapiUninit. The CeRapiInitEx function does not block the calling thread. Instead, it uses an event to signal when initialization is complete."
Is there a way to determine if a PPC is connected before invoking the CeRapiInit() statement? Am I using the CeRapiInit() call correctly?
I speculate from the documentation that perhaps another thread should be started that calls CeRapiUninit after a certain time period. Or perhaps I should use CeRapiInitEx with a timeout handler?
I'd appreciate a small program that shows code how to accomplish this.
TIA
The eVC 3.0 documentation indicates:
"A call to CeRapiInit does not return until the connection is made, an error occurs, or another thread calls CeRapiUninit. The CeRapiInitEx function does not block the calling thread. Instead, it uses an event to signal when initialization is complete."
Is there a way to determine if a PPC is connected before invoking the CeRapiInit() statement? Am I using the CeRapiInit() call correctly?
I speculate from the documentation that perhaps another thread should be started that calls CeRapiUninit after a certain time period. Or perhaps I should use CeRapiInitEx with a timeout handler?
I'd appreciate a small program that shows code how to accomplish this.
TIA
ASKER
Thanks for replying, but I'm looking for more than copy/paste from the CeRapiInitEx documentation. I'd already looked at the function doc and was puzzled how to get this to work.
I'll increase the points and re-request a simple code example.
TIA,
I'll increase the points and re-request a simple code example.
TIA,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry to be slow checking on a reply. I'll try out your code snippet and, hopefully it will work and I'll release the points.
Thanks,
Thanks,
ASKER
Thanks chensu.
Your code cleared up my questions and pretty much worked as supplied. I changed the QS_ALLINPUT to QS_TIMER, and I'm a bit surprised the &ri.heRapiInit worked ok as the 2nd arg to MsgWaitForMultipleObjects. The documentation calls for an array of HANDLE's.
This is the code I'm proceeding with. Any suggestions?
BOOL okFlag = FALSE;
DWORD rc;
RAPIINIT ri = {
RAPIINIT ri = { sizeof(RAPIINIT), NULL, NULL };
hRapiResult = ::CeRapiInitEx(&ri);
HANDLE handles[2] = { ri.heRapiInit, NULL };
if (SUCCEEDED(hRapiResult)) {
rc = MsgWaitForMultipleObjects( 1, handles, FALSE, 5000, QS_TIMER);
if (rc == WAIT_OBJECT_0) {
if (SUCCEEDED(ri.hrRapiInit)) {
okFlag = TRUE;
}
}
}
if (okFlag == FALSE) {
::MessageBox(NULL, "Unable to initialize (timed out). Is Pocket-PC connected?",
APP_EXE_NAME " Pocket PC",
MB_OK | MB_ICONSTOP);
return;
}
Thanks again.
Your code cleared up my questions and pretty much worked as supplied. I changed the QS_ALLINPUT to QS_TIMER, and I'm a bit surprised the &ri.heRapiInit worked ok as the 2nd arg to MsgWaitForMultipleObjects.
This is the code I'm proceeding with. Any suggestions?
BOOL okFlag = FALSE;
DWORD rc;
RAPIINIT ri = {
RAPIINIT ri = { sizeof(RAPIINIT), NULL, NULL };
hRapiResult = ::CeRapiInitEx(&ri);
HANDLE handles[2] = { ri.heRapiInit, NULL };
if (SUCCEEDED(hRapiResult)) {
rc = MsgWaitForMultipleObjects(
if (rc == WAIT_OBJECT_0) {
if (SUCCEEDED(ri.hrRapiInit))
okFlag = TRUE;
}
}
}
if (okFlag == FALSE) {
::MessageBox(NULL, "Unable to initialize (timed out). Is Pocket-PC connected?",
APP_EXE_NAME " Pocket PC",
MB_OK | MB_ICONSTOP);
return;
}
Thanks again.
Using &ri.heRapiInit works OK because the first parameter of MsgWaitForMultipleObjects( ) is one to indicate that there is only one element in the array.
"After calling CeRapiInitEx, check the return value to see if an error occurred. If the call was initially successful, call the MsgWaitForMultipleObjects function to wait on the event handle passed back in the heRapiInit member of the RAPIINIT structure. When the event is set, check the hrRapiInit member of the structure to determine if the connection was successful."