Writing services for the WinCE 6.0 Kernel


When rewriting services.exe for the CE 6.0 kernel, we tried to make it so that as few changes as possible were required for service writers.


Unlike application BC (which is critical), there were some places in services.exe where your service may need to be reworked for the new kernel.  Some of these were unavoidable (like the virtual memory changes).  There are some archane features listed below that we decided not to continue supporting because they weren't being used (some are actually being doc'd for the first time below!) and would have required hacking up the kernel.


Changes for CE 6.0 services writers:


• The virtual memory model for Windows CE has changed.  Previously, each application was limited to a 32 megabyte virtual address space.  Now each application has a 4 gigabyte virtual address space.  Because of this, services cannot directly access pointers when processing a PSL call as they could previously.  Sue Loh has a good blog about pointer access in general at the ce_base blog.  Servicesd.exe behaves just like udevice.exe in her model.


• Previously, the process named services.exe served both as the host for service DLLs (when it was the first services.exe instance created on a system) and a command line interpreter allowing operations on services such as stopping, starting, etc...  In Windows CE 6.0, the process that hosts service DLLs is now named servicesd.exe.  Services.exe process only acts as a command line interpreter.


• The “Context” registry value for service DLLs must not be used.  For configuring options such as SERVICE_INIT_STOPPED (0x00000001), this registry value should be “ServiceContext”.  Setting Context to a non zero value will cause servicesd.exe to not load your service.


• The ability to instantiate an additional (limited functionality) copy of services.exe to host a service in its own process space has been removed.  This was previously enabled via the SERVICE_INIT_STANDALONE Context flag.


• In previous versions of Windows CE, from the services command line a user could enter “services command <servicePrefix> arg1 arg2 arg3 …” and have the arguments passed to given service via the IOCTL  IOCTL_SERVICE_COMMAND_LINE_PARAMS.  This functionality is no longer supported in Windows CE 6.0.


• In previous versions of Windows CE, services.exe queried a service with IOCTL_SERVICE_QUERY_CAN_DEINIT prior to unloading it.  The service could indicate it did not wish to be unloaded using this mechanism.  This is no longer supported.  Services can indicate that they should never be unloaded by setting DEVFLAGS_NOUNLOAD “Flags” registry value.
--


My experience for pure network services (like say web server) was pretty good, where the service required few if any changes.  I had to port +10 services to the new kernel personally.  So I had selfish motivation for keeping services.exe as close as possible to the way it used to be in addition to my concern for you folks who are writing my paycheck.


A service like the web service is pretty much an application as far as the system is concerned that just happens to run in services.  Services that make more extensive use of interprocess communication (where the service is a service for API calls on device as opposed to or addition to being a networking service) were hard or easy, depending on how complicated the API was.  MSMQ took me two weeks to port to the new kernel, because it has tons of arrays of VARIANTs of pointers that all had to be marshalled over.  LPC (the underlying piece of interprocess COM) took 3 weeks, though half of this was me trying to figure out the innards of LPC & DCOM.  However these all had to do with virtual memory and not services.exe specific stuff.


[Author: John Spaith]

Comments (3)
  1. John Spaith has posted some information about porting services to CE 6.0 – here’s a link to the blog

  2. Hi,

    This is Rajendran. I need your help.

    I couldn’t load/start my own Services in WinCE 6.0 ARMV4I emulator.

    Could you please tell me how can I start my services in WinCE 6.0?

    The following steps I did for creating new services.

    1. Add new sub project in Platform builder
    2. Added the following setting in Def file

    LIBRARY     WCEService

    EXPORTS

    WCE_Init

    WCE_Deinit

    WCE_Open

    WCE_Close

    WCE_IOControl

    1. Added the folllowing setting in reg file

    [HKEY_LOCAL_MACHINEServicesWCEService]

    "DLL"="WCEService.dll"

    "Prefix"="WCE"

    "Order"=dword:9

    "Index"=dword:0

    "Keep"=dword:1

    "DisplayName"="WCE Sample Service"

    "Flags"=dword:0

    1. I have implmented all functions which are mentioned in above def file.
  3. Start building

  4. WCEService.dll has been copied in /windows folder in Windows 6.0 ARMV4I Emulator.

  5. In cmd/console window, I type the following command

  6. Services –d List

    362694 PID:7a1000a TID:7a2000a FAP0: 0x00000000 USBFlashAPService.dll

    362696 PID:7a1000a TID:7a2000a Running

    362696 PID:7a1000a TID:7a2000a NTP0: 0x00000000 timesvc.dll

    362696 PID:7a1000a TID:7a2000a Running

    362696 PID:7a1000a TID:7a2000a LOC0: 0x00000000 LFSVC.Dll

    362696 PID:7a1000a TID:7a2000a Running

    362696 PID:7a1000a TID:7a2000a IGD1: 0x00000000 IGD.dll

    362696 PID:7a1000a TID:7a2000a Running

    362696 PID:7a1000a TID:7a2000a UPL1: 0x00000000 upnploader.dll

    362697 PID:7a1000a TID:7a2000a Running

    362697 PID:7a1000a TID:7a2000a GPD0: 0x00000000 GPSID.dll

    362697 PID:7a1000a TID:7a2000a Running

    362697 PID:7a1000a TID:7a2000a RBT0: 0x00000000 ROUTENBTD.Dll

    362697 PID:7a1000a TID:7a2000a Running

    362697 PID:7a1000a TID:7a2000a BTM1: 0x00000000 BTMODEM.Dll

    362697 PID:7a1000a TID:7a2000a Running

    362697 PID:7a1000a TID:7a2000a BTS1: 0x00000000 BTSVC.Dll

    362733 PID:7a1000a TID:7a2000a Running

    362734 PID:7a1000a TID:7a2000a HTP0: 0x00000000 HTTPD.DLL

    362734 PID:7a1000a TID:7a2000a Running

    362755 PID:7a1000a TID:7a2000a UPP1: 0x00000000 upnpsvc.dll

    362755 PID:7a1000a TID:7a2000a Running

    362755 PID:7a1000a TID:7a2000a DCM1: 0x00000000 dcomssd.dll

    362755 PID:7a1000a TID:7a2000a Unknown

    362755 PID:7a1000a TID:7a2000a LPC1: 0x00000000 lpcd.dll

    362788 PID:7a1000a TID:7a2000a Unknown

    I couldn’t see my Services in the list

    1. Then I typed the following command to load my serices then I got error only

    c> Services –d load WCEService

    354703 PID:6ff000a TID:700000a Operation failed.  Error code 0x0000006e

    c> Services –d load WCE0:

    584217 PID:7d4000a TID:7d5000a Operation failed.  Error code 0x0000064a

    There is no document for start and load services. Please tell me how to do this.

    Where can I find the meaning of above error codes?

    Thanks,

    Rajendran

  • cenet says:

    Rajendran – sorry for long delay.  I’d recommend in general newsgroups (http://blogs.msdn.com/cenet/archive/2005/12/05/500181.aspx) as a better communication mechanism that have a bigger audience.

    For this problem, the Services –d load WCEService is what you want, not the "WCE0:".  It’s not clear from error code why the load failed, probably the best thing to do if you still have issues would be to post on newsgroup and to get a debug devmgr.dll, device.dll, udevice.exe, and servicesd.exe into your image (you can just use a full debug build ideally, failing that check out http://blogs.msdn.com/cenet/archive/2007/04/09/how-to-drop-a-debug-dll-into-a-windows-ce-device.aspx for how to get specific debug images) and turn up debugzones and see if anything is obvious on the "Services -d load…", if not post on newsgroup.

    Again sorry for delay here.

    John

  • Comments are closed.

    Skip to main content