2010年10月29日 星期五

Mobile Service Development

Notes of study “Implement a Network Service on Windows CE”. I think this article is a good start point of learning mobile service development.

Export functions

The service library file need to exports these methods at least.

XXX_Init

XXX_Deinit

XXX_Open

XXX_Close

XXX_IOControl

If your service designed to provide stream interface, more methods need to be exported.

XXX_Read

XXX_Seek

XXX_Write

The detail definition of those method can find on MSDN, just search “XXX_{method name}” (yes, I mean “XXX”).

Service Registry

Follow the article, you can find the document link of service.exe’s registry setting.

I used one more registry than the sample: “Keep: 1”. According to the registry document, the value 0 cause service.exe unload the library after initialization, and that is not what I want.

And you need to notice another thing is “Context: 1”. The registry document describe that the value is the input parameter of XXX_Init() function. But actually the value 1 in this sample is for purpose. The value 1 is a special number that tells services.exe this service want to use super service (the socket control by services.exe).

Service State

One IOCTL in that sample need to be notice: IOCTL_SERVICE_STARTD.

This IOCTL used for super service to indicate all ports have been opened. If your service does not use super service, don’t listen this IOCTL and don’t let your service state relay on it.

Services.exe command line

The article describes the usage of services.exe command line. It is vary useful for start/stop your service for test. But actually, we don’t have console and the command line function has been disabled on Windows Mobile 6 device.

So, let’s make it work.

First, find and install PocketCMD. It can be found on network easily. But you need to modify a registry to make it work.

HKEY_LOCAL_MACHINE\Drivers\Console\OutputTo

By default, there will be a strange number of this registry, set it to “0”, and your PocketCMD should be ready.

But when you try to execute services.exe on console, you will always get error 0x00000005 (ERROR_ACCESS_DENY), that is cause by services.exe command line function has been disabled. Again, modify the registry to release it.

HKEL_LOCAL_MACHINE\Services\AllowCmdLine

Done. Now you can follow the steps on that article to debug your service.

Certification

Before I test my service, my colleague told me that the service library need to be signed for services.exe to run. I did not find document describe this limitation, but it really exists.

After I made my first service library follow the article, I cannot see it be run when device start up. But I can launch the service by services.exe command line tool, and it looks run well.

So, I try to create a test CA and install it on my device. And then I sign the service library with my test CA. Everything is fine. Now my service can be start up automatically when device start up

The detail about create and use the test CA, you can refer this.

沒有留言:

張貼留言