Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Detect PPC before CeRapiInit hangs

Posted on 2003-03-29
6
Medium Priority
?
733 Views
Last Modified: 2013-12-27
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
0
Comment
Question by:ee-user
  • 3
  • 3
6 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 8234823
Use CeRapiInitEx instead.

"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."
0
 

Author Comment

by:ee-user
ID: 8261275
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,
0
 
LVL 23

Accepted Solution

by:
chensu earned 1200 total points
ID: 8266677
// NOT TESTED CODE

RAPIINIT ri = { sizeof(RAPIINIT) };

if (SUCCEEDED(::CeRapiInitEx(&ri)))
{
    // Time out: 90 seconds, the last parameter depends on what you need.
    switch (::MsgWaitForMultipleObjects(1, &ri.heRapiInit, FALSE, 90000, QS_ALLINPUT))
    {
        case WAIT_OBJECT_0:
            if (SUCCEEDED(ri.hrRapiInit))
            {
                // Succeeded.
            }
            break;

        case WAIT_OBJECT_0 + 1:
            // A message arrives, maybe put a message loop here.
            break;

        case WAIT_TIMEOUT:
            // Time out
            break;

        default:
            // Should not happen
            break;
    }

    ::CeRapiUninit();
}
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 

Author Comment

by:ee-user
ID: 8591748
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,
0
 

Author Comment

by:ee-user
ID: 8604421
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.
0
 
LVL 23

Expert Comment

by:chensu
ID: 8607190
Using &ri.heRapiInit works OK because the first parameter of MsgWaitForMultipleObjects() is one to indicate that there is only one element in the array.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question