/* GLOBALS ******************************************************************/
-static VOID CALLBACK
-ServiceMain(DWORD argc, LPTSTR *argv);
-
-static SERVICE_TABLE_ENTRY ServiceTable[2] =
+static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
+static WCHAR ServiceName[] = L"PlugPlay";
+static SERVICE_TABLE_ENTRYW ServiceTable[] =
{
- {TEXT("PlugPlay"), ServiceMain},
+ {ServiceName, ServiceMain},
{NULL, NULL}
};
+static SERVICE_STATUS_HANDLE ServiceStatusHandle;
+static SERVICE_STATUS ServiceStatus;
+
static WCHAR szRootDeviceId[] = L"HTREE\\ROOT\\0";
static HKEY hEnumKey = NULL;
RpcServerThread(LPVOID lpParameter)
{
RPC_STATUS Status;
+ BOOLEAN RegisteredProtSeq = FALSE;
UNREFERENCED_PARAMETER(lpParameter);
DPRINT("RpcServerThread() called\n");
+#if 0
+ /* XP-compatible protocol sequence/endpoint */
Status = RpcServerUseProtseqEpW(L"ncacn_np",
20,
- L"\\pipe\\umpnpmgr",
+ L"\\pipe\\ntsvcs",
NULL); // Security descriptor
- if (Status != RPC_S_OK)
- {
+ if (Status == RPC_S_OK)
+ RegisteredProtSeq = TRUE;
+ else
DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
+#endif
+
+ /* Vista-compatible protocol sequence/endpoint */
+ Status = RpcServerUseProtseqEpW(L"ncacn_np",
+ 20,
+ L"\\pipe\\plugplay",
+ NULL); // Security descriptor
+ if (Status == RPC_S_OK)
+ RegisteredProtSeq = TRUE;
+ else
+ DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
+
+ /* Make sure there's a usable endpoint */
+ if (RegisteredProtSeq == FALSE)
return 0;
- }
Status = RpcServerRegisterIf(pnp_v1_0_s_ifspec,
NULL,
/* Function 56 */
DWORD PNP_QueryArbitratorFreeData(
- handle_t hBinding)
+ handle_t hBinding,
+ BYTE *pData,
+ DWORD DataLen,
+ LPWSTR pDeviceID,
+ RESOURCEID ResourceID,
+ DWORD ulFlags)
{
UNIMPLEMENTED;
return CR_CALL_NOT_IMPLEMENTED;
/* Function 57 */
DWORD PNP_QueryArbitratorFreeSize(
- handle_t hBinding)
+ handle_t hBinding,
+ DWORD *pulSize,
+ LPWSTR pDeviceID,
+ RESOURCEID ResourceID,
+ DWORD ulFlags)
{
UNIMPLEMENTED;
return CR_CALL_NOT_IMPLEMENTED;
}
+static VOID
+UpdateServiceStatus(DWORD dwState)
+{
+ ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ ServiceStatus.dwCurrentState = dwState;
+ ServiceStatus.dwControlsAccepted = 0;
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwServiceSpecificExitCode = 0;
+ ServiceStatus.dwCheckPoint = 0;
+
+ if (dwState == SERVICE_START_PENDING ||
+ dwState == SERVICE_STOP_PENDING ||
+ dwState == SERVICE_PAUSE_PENDING ||
+ dwState == SERVICE_CONTINUE_PENDING)
+ ServiceStatus.dwWaitHint = 10000;
+ else
+ ServiceStatus.dwWaitHint = 0;
+
+ SetServiceStatus(ServiceStatusHandle,
+ &ServiceStatus);
+}
+
+
+static DWORD WINAPI
+ServiceControlHandler(DWORD dwControl,
+ DWORD dwEventType,
+ LPVOID lpEventData,
+ LPVOID lpContext)
+{
+ DPRINT1("ServiceControlHandler() called\n");
+
+ switch (dwControl)
+ {
+ case SERVICE_CONTROL_STOP:
+ DPRINT1(" SERVICE_CONTROL_STOP received\n");
+ UpdateServiceStatus(SERVICE_STOPPED);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_PAUSE:
+ DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
+ UpdateServiceStatus(SERVICE_PAUSED);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_CONTINUE:
+ DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
+ UpdateServiceStatus(SERVICE_RUNNING);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_INTERROGATE:
+ DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
+ SetServiceStatus(ServiceStatusHandle,
+ &ServiceStatus);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_SHUTDOWN:
+ DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
+ UpdateServiceStatus(SERVICE_STOPPED);
+ return ERROR_SUCCESS;
+
+ default :
+ DPRINT1(" Control %lu received\n");
+ return ERROR_CALL_NOT_IMPLEMENTED;
+ }
+}
+
+
static VOID CALLBACK
ServiceMain(DWORD argc, LPTSTR *argv)
{
DPRINT("ServiceMain() called\n");
+ ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
+ ServiceControlHandler,
+ NULL);
+ if (!ServiceStatusHandle)
+ {
+ DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
+ return;
+ }
+
+ UpdateServiceStatus(SERVICE_START_PENDING);
+
hThread = CreateThread(NULL,
0,
PnpEventThread,
if (hThread != NULL)
CloseHandle(hThread);
+ UpdateServiceStatus(SERVICE_RUNNING);
+
DPRINT("ServiceMain() done\n");
}