views:

85

answers:

1

For accessing Windows CE devices from my desktop application I used self-written DLL. This DLL used RAPI to call necessary functions on device side. Everything has been working fine for years.

But now I wanted to use this DLL in Windows service. And it failed. Debug shows that it is CeRapiInitEx() function that fails. And before failing it blocks for about 5 seconds, although MSDN says it is an asynchronous non-blocking function. GetLastError() gives me 1444L "Invalid thread identifier".

Someone on the internet mentioned that RAPI did not work from service threads in ActiveSync 4. Though the information is poor and scrappy.

Does anyone have the same problem or just have something to say? Is it true that RAPI is not accessible from Windows Service? If so, are there any workarounds?

A: 

Possible solutions for this problem:

  1. Downgrade ActiveSync to version 3.8 and give the service permission to interact with desktop (use system Services applet for this).
  2. Spawn another user process (CreateProcessAsUser) and use it as interlayer between the service and RAPI (i.e., make all RAPI calls in this process).
  3. Create another user (non-service) application, and use it as interlayer between the service and RAPI (i.e., make all RAPI calls in this application).
  4. Run service code as usual (e.g., console) application.
  5. Switch from RAPI to another interfaces to communicate with device, e.g. TCP.

I've chosen 1st, personally, since it's the most suitable in my case.

Alex Che