Can't find PInvoke DLL 'rapi.dll'.

Jul 22, 2009 at 7:22 PM


I'm getting an error - "Can't find PInvoke DLL 'rapi.dll'." when trying to run my app.

I have CE5 with .Net 2.0. I have donwloaded the OpenNetCF Desktop Communication Librray project ( brillinat - thanks !  :-) ), built the library and referenced the dll in my project.

I can refernece the RAPI class via the OpenNETCF.Desktop.Communication namespace, and it all builds load neatly. but when executing I get the  error above.

Can you please suggest where I may be going wrong.  here's my statement

        Conn = New OpenNETCF.Desktop.Communication.RAPI()

In my solution properties, Copy Local for the referenced dll is set to TRUE.

Guidance wold be much appreciated, thanks ! :-)


Jul 22, 2009 at 8:49 PM


The rapi.dll is the native win32 library where OpenNETCF.Desktop.Communication.RAPI is P/invoking the required functions from. Its normal that p/invoke errors that are caused by a missing library file aren't throwing any compile time errors because the target dll won't be accessed before runtime.

Well, do you have activesync installed? If so, make sure you are running version 4.5.

If i remember correctly the rapi.dll should be located in /windows/system32/.


Jul 22, 2009 at 11:10 PM

HI Rev,

Thanks for your reply.

Perhaps I have misunderstood the function of the library - my intention was to detect if the remote device is connected to Activesync.  The code sample - and error message - are generated on my Win CE device.

From your suggestions, I assume that the OpenNETCF.Desktop.Communication librray is for desktop apps - is there a counterpart for the remote device to detect an active ActiceSync connection ?

Thanks for your help


Jul 23, 2009 at 8:03 AM


Yes, OpenNETCF.Desktop.Communication librray is for desktop apps only because it depends on desktop win libraries.

For the device there are a few ways.

1. There maybe some SDK for your windows CE device that provides the required functionality.

2. I've read that for windows mobile there is Microsoft.WindowsMobile.Status class. But not sure about that one and you are on CE5 anyway.

3. For generic CE devices, you can P/Invoke the CeRunAppAtEvent (which can set an event, not just run an app) with the NOTIFICATION_EVENT_RS232_DETECTED flag.

4. Use OpenNETCF's Smart Device Framework 2.2 Community Edition. Take a look at the DeviceManagement class that exposes the SerialDeviceDetected event. (its  probably  wrapping whats mentioned in 3.)

 So far i always used the device SDK for this kind of stuff. However, you probably want to try option 4.


Jul 23, 2009 at 9:40 AM


Thanks for your answer - most appreciated.

I had been looking for an SDK, which is how I got to OpenNETCF :-))

Yes, I had read that there is support in WM5, but it's not supported in CE5, which I need.

The CERunAppAtEvent appears not to provide a 'disconnected' status, which is why I had not explored that.

The SmartDeviceFramework may provide what I need - I shall take a look at that .

Many thanks for your help,


Mar 4, 2014 at 7:38 PM
Edited Mar 4, 2014 at 7:49 PM

I am receiving the same error'Can't find PInvoke DLL 'rapi.dll'.

I placed the OpenNETCF.Desktop.Communication.dll in C:/windows/system32/ and since my system is running on Windows 7 I have Windows Mobile Device Center instead of Active Sync.

Could you please let me know a solution for this?


Please ignore this post; I realized I was trying to invoke RAPI.dll from an application running on the mobile device instead of desktop application