PrashantWaman

Hi all,
i have created one service called MYS.DLL which is a sample service available on net.
It works fine on Pocket PC 2003, but it failed on Windows Mobile 5.0. The steps followed by me are as follows
1. Compiled SampleService project for windows mobile 5.0
2. created one smart device cab project and added the MYS.DLL file in windows directory in the cab project.
3. Opened Registry editor from cab project and added following registry entries in it.
  "Dll"="MYS.DLL"
"Order"=dword:9
"Keep"=dword:1
"Prefix"="MYS"
"Index"=dword:0
"Context"=dword:1
"DisplayName"="Sample Services"
"Description"="Sample Services"
"Flags"="dword:0
also i tried with
"Flags"="dword:2

4. copied the cab file to emulator through active sync
5. executed the cab file.
6. checked that the MYS.DLL is in windows directory and all the registery
entries are properly set.
7. soft rebooted the emulator.

The service is not get activated on windows mobile 5.0

where i am gone wrong if possible please provide me some code sample and
registry settings.

thanks




Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Christopher Fairbairn

Hi,

One thing to check is that in the move from a 2003 to a 2005 project some of the compiler settings havn't been changed or forgotten about.

If you use the dumpbin or depends utilities which come with Visual Studio you should be able to view the functions your DLL exports. These should match the names in your source code. If they have random numbers etc after the name then this is most likely your problem. If this is the case I would look for any compiler settings (such as CPP Macro definitions which are missing in your newly created Visual Studio 2005 project file but are present in the 2003 project).

Although it is targeted for Compact framework developers the following MSDN article should help you find the dumpbin utility and give you an explination on how to utilise it - http://msdn2.microsoft.com/en-us/library/aa446532.aspx

Hope it helps,

Christopher Fairbairn






Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Stefano_Azzi

In Windows Mobile 5 for running a service you need to use a DLL signed with a privileged certificate or security-off your device.

http://msdn2.microsoft.com/en-us/library/ms839681.aspx

http://www.pocketpcfaq.com/faqs/provisioning/provisioning.htm





Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

PrashantWaman

Hi,
i checked the dll exported functions in depends and found following result without any name mangling.

MYS_Close
MYS_Deinit
MYS_IOControl
MYS_Init
MYS_Open
MYS_Read
MYS_Seek
MYS_Write

i don't think i have a problem with configuration as i created a new project in 2005 for ppc windows mobile 5.0 and then simply added the MYS cpp file from old(windows mobile 2003) project.

where i might be wrong is the registry settings or may be wm5.0 requires some change in code.
But i unable to find any document for wm5.0.

reply soon.

thanks,





Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

PrashantWaman

Hi,

I am testing my service on emulators so are the emulators require such singning of dll

regards,





Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Stefano_Azzi

Yes, this utility help you to Secure/Unsecure your device:

http://www.microsoft.com/downloads/details.aspx FamilyID=7e92628c-d587-47e0-908b-09fee6ea517a&displaylang=en





Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

PrashantWaman

hi,
Thanks for the reply.
i have downloaded the Security Configuration Manager and signed my dll and cab file with priviledged development certificate. Also i provisioned the Security Off configuration to the emulator, but still i can't able to run my service on wm5.0.

As i can see my MYS.DLL at proper location (i.e. windows folder )through remote file viewer and all registry entries added through remote registry viewer, i think there is not a issue of signing.
please correct me if i am wrong.

anyway the problem is still there. I am unabled to start a serive on wm5.0. waiting for some help.

thanks,






Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Stefano_Azzi

Read this example.

http://www.pocketpcdn.com/articles/services.html

Code Snippet


DWORD MYS_Close(DWORD dwData)
{
return 0;

}

DWORD MYS_Deinit(DWORD dwData)
{
return 0;
}

DWORD MYS_Init(DWORD dwData)
{
// MessageBox for test
MessageBox(0, _T("Test"), _T("Test"), NULL);
}

DWORD MYS_IOControl(
DWORD dwData,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut)
{
return 1;
}

DWORD MYS_Open(
DWORD dwData,
DWORD dwAccess,
DWORD dwShareMode)
{
return 0;
}

DWORD MYS_Read(
DWORD dwData,
LPVOID pBuf,
DWORD dwLen)
{

return 0;
}

DWORD MYS_Seek(
DWORD dwData,
long pos,
DWORD type)
{

return 0;
}

DWORD MYS_Write(
DWORD dwData,
LPCVOID pInBuf,
DWORD dwInLen)
{

return 0;
}





Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

PrashantWaman

hi,
i got the solution.
The steps followed are as follows.
1. created MYS.DLL
2. created a cab project.
3. copied the cab project and executed.
4. soft reset the emulator. But service not started.
5. created an application to start the service using ActivateService.
6. copied the exe to emulator and executed.
The service get started.

The conclusion was, the service is not getting started at booting time and we need to activate it manually.

i can't find why it is not activating at booting time. any reason for it

after searching over net, i found that the at booting time os checks for the certificates of the service and hence can't start it. when we activate it manually, certificate are not getting checked, hence it get started. Is this a reason for it

But when i checked my dll and cab files, both having the proper certificates with them.
Hence still i am confused that why it is not working at booting time. any conclusion

regards,





Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Stefano_Azzi

Mhh....in the registry you have this key with this value

[HKEY_LOCAL_MACHINE\Services\MyServ] &quot;Dll&quot;=&quot;MYS.dll&quot; &quot;Order&quot;=dword:8 &quot;Keep&quot;=dword:1 ----&gt; most important to be &quot;1&quot; &quot;Prefix&quot;=&quot;MYS&quot; &quot;Index&quot;=dword:0 &quot;Context&quot;=dword:0 &quot;DisplayName&quot;=&quot;Sample MFC Service&quot; &quot;Description&quot;=&quot;Sample Service demonstratig MFC usage&quot;<font face="Geneva, Arial, Sans-serif"> Another test is :</font>
  1. Signing your MSY.dll and avoid to create a CAB
  2. Copy your signed DLL in the \Windows device folder
  3. Copy and install the privileged certificate into device
  4. Put the above information in the registry (remember to put 1 in Keep)




Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Zero Dai - MSFT

Hi,

Yes, the executable file of your service must be signed privileged if it is loaded at boot time. That means you need to sign your service dll file with a certificate that is in the privileged certificate store on your emulator/device. So, when you sign it, make sure the certificate is type of privileged.

Another solution for your problem is to write an executable, which call RegisterService() function to load your service. And put this executable in Startup folder. Thus, you don't need to sign your service privileged, and it can also be loaded.

Here is a very good article on Windows Mobile Application Security, you may want to read it:

http://msdn2.microsoft.com/en-us/library/ms839681.aspx

Thanks,

Zero Dai - MSFT






Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

Christopher Fairbairn

Hi,

Here's a good blog posting summarising this behaviour - http://blogs.msdn.com/windowsmobile/archive/2005/11/03/488934.aspx

I have a feeling (but havn't investigated recently) that signing with the Visual Studio 2005 provided developer certificates doesn't help in this scenario either, due to the similiar behaviour of the device still being in a state of initialisation.

Hope it helps,

Christopher Fairbairn






Re: Smart Devices Native C++ Development Not working services for Windows mobile 5

PrashantWaman

Hi,

Thanks for the urls.

regards,