is there anyway to check if pocket pc is connected to desktop via activesync?

Dani AI

Generated

Quick summary to complement the replies: is right that wrappers like OpenNETCF make this easier, but if you must avoid that library there are two reliable approaches — detect from the desktop (RAPI) or detect on the device (State & Notification broker). Below are concise, practical options and the usual gotchas.

Desktop-side (canonical): use RAPI. Call CeRapiInit (or CeRapiInitEx to get an event handle) to initialize RAPI; a successful init means a device is reachable and you can do RAPI operations. CeRapiInit blocks until connect/error, so run it on a background thread and always call CeRapiUninit when finished. RAPI/rapi.dll is provided by ActiveSync/Windows Mobile Device Center, so the desktop component must be installed and running.

[DllImport("rapi.dll")]
private static extern int CeRapiInit();
[DllImport("rapi.dll")]
private static extern int CeRapiUninit();

// run on a worker thread:
int hr = CeRapiInit();
bool devicePresent = (hr == 0); // S_OK
if (devicePresent) { /* use RAPI */ }
CeRapiUninit();

(learn.microsoft.com)

Device-side: for Windows Mobile apps use the State & Notification broker (Microsoft.WindowsMobile.Status). Check SystemState.CradlePresent or SystemProperty.ConnectionsDesktopCount (or subscribe to changes) to know when the device is cradled / has desktop connections. This is lightweight and avoids desktop-side dependencies.

using Microsoft.WindowsMobile.Status;
bool cradled = SystemState.CradlePresent;
int desktopCount = (int)SystemState.GetValue(SystemProperty.ConnectionsDesktopCount);

(learn.microsoft.com)

Short troubleshooting tips: run any RAPI init off the UI thread; ensure ActiveSync/WMDC is installed and the device accepted the trust/partnership prompt; if you see rapi.dll errors check that your desktop build/installer matches the installed WMDC/ActiveSync bitness; to get attach/detach events on the PC you can also watch WM_DEVICECHANGE / RegisterDeviceNotification. If you prefer a managed wrapper for convenience, OpenNETCF is the usual choice (as originally suggested). (support.tracerplus.com)

Recommended Answers

All 5 Replies

Check out the OpenNetCF Desktop Communication Library. It is available here:

i am not supposed to use opennetcf libraries for some reason.
thanks.

Well the opennetcf library is open source, so you can at least download the source and see how they do it.

thanks, i will give it a try.

i found very good solution to this problem
http://www.daniweb.com/forums/thread199591.html
this solution does not use opennetCF. so instead of adding that big library and all the licensing issues you just add few lines of code to your application. this is serkan sendur style. someone has to add to my reputation for this thread as i can not add to mine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.