Detect PPC before CeRapiInit hangs

Posted on 2003-03-29
Medium Priority
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.

Question by:ee-user
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 23

Expert Comment

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

Author Comment

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.

LVL 23

Accepted Solution

chensu earned 1200 total points
ID: 8266677

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.

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

        case WAIT_TIMEOUT:
            // Time out

            // Should not happen

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

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.


Author Comment

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;

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);

Thanks again.
LVL 23

Expert Comment

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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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