我参照msdn上wince服务的介绍写了个服务,但好像一直没有被系统调用,大家帮忙看下原因.
appKey.SetValue("Dll", "MyMobileService.dll");
appKey.SetValue("Order", "10", RegistryValueKind.DWord);
appKey.SetValue("Prefix", "CU");
appKey.SetValue("Index", "0", RegistryValueKind.DWord);
appKey.SetValue("Context", "1", RegistryValueKind.DWord);
这个是写注册表的部分.
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
WriteDebugText("begin attach process\r\n");
g_dwServiceState = SERVICE_STATE_UNINITIALIZED;
InitializeCriticalSection(&g_cs);
DisableThreadLibraryCalls((HMODULE)hModule);
DEBUGREGISTER((HINSTANCE)hModule);
break;
case DLL_PROCESS_DETACH:
WriteDebugText("begin detach process\r\n");
DeleteCriticalSection (&g_cs);
break;
}
return TRUE;
}
DWORD CU_Close(DWORD dwData)
{
WriteDebugText("service closed!\r\n");
return 0;
}
DWORD CU_Deinit(DWORD dwData)
{
WriteDebugText("begin deinit services\r\n");
DEBUGMSG(ZONE_INTRF,(L"CUFriends: CU_DeInit(0x%08x)\r\n",dwData));
EnterCriticalSection (&g_cs);
g_dwServiceState = SERVICE_STATE_UNLOADING;
LeaveCriticalSection(&g_cs);
DEBUGMSG(ZONE_INIT,(L"CUFriends: Completed shutdown. Returning to "
L"services.exe for unload\r\n"));
return 0;
}
DWORD CU_Init(DWORD dwData)
{
WriteDebugText("begin init services\r\n");
DEBUGMSG(ZONE_INTRF,(L"CUFriends: CU_Init(0x%08x)\r\n",dwData));
EnterCriticalSection (&g_cs);
if (g_dwServiceState != SERVICE_STATE_UNINITIALIZED) {
DEBUGMSG(ZONE_ERROR,(L"CUFriends: ERROR: CUFriends service already "
L"initialized on CU_Init() call\r\n"));
LeaveCriticalSection (&g_cs);
return 0;
}
g_dwServiceState = SERVICE_STATE_STARTING_UP;
DEBUGMSG(ZONE_INIT,(L"CUFriends: CU_Init success - service is "
L" in starting up state\r\n"));
LeaveCriticalSection (&g_cs);
return 1;
}
......
void WriteDebugText(char* msg)
{
FILE* fl = fopen("logfile.txt", "a+" );
fwrite(msg, sizeof(char), strlen(msg), fl);
fclose(fl);
}
上面是dll中的主要代码.
LIBRARY "MyMobileService"
EXPORTS
CU_Close
CU_Deinit
CU_Init
CU_IOControl
CU_Open
CU_Read
CU_Seek
CU_Write
这个是def文件.
目标设备是CHS WM5.0 ppc r2 emulator
我把注册表项写入了模拟器,用远程注册表查看工具看过了,应该没问题.
然后把MyMobileService.dll文件拷贝到了模拟器的windows目录下.
软重置模拟器,发现日志文件没有被创建,并且发现MyMobileService.dll模块根本不在Service进程内.
还望大家帮忙解决下.还有,我怎么在模拟器上调试MyMobileService.dll的代码呢?
本人新手,大家说得越详细越好.
模拟器,没试过,手机上的话需要将服务程序sign后才会生效。