From 32233377461bcf78b509b51c3b3a9a6a1684e67d Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Thu, 29 Oct 2009 21:58:42 +0200 Subject: [PATCH] wiaservc: Add wiaservc.dll and implement its svchost entrypoint. --- configure | 9 +++ configure.ac | 1 + dlls/wiaservc/Makefile.in | 14 ++++ dlls/wiaservc/service.c | 142 ++++++++++++++++++++++++++++++++++ dlls/wiaservc/wiaservc.spec | 57 ++++++++++++++ dlls/wiaservc/wiaservc_main.c | 56 ++++++++++++++ 6 files changed, 279 insertions(+) create mode 100644 dlls/wiaservc/Makefile.in create mode 100644 dlls/wiaservc/service.c create mode 100644 dlls/wiaservc/wiaservc.spec create mode 100644 dlls/wiaservc/wiaservc_main.c diff --git a/configure b/configure index 2e5c03831b1..2b45c319892 100755 --- a/configure +++ b/configure @@ -16958,6 +16958,14 @@ ALL_MAKEFILE_DEPENDS="$ALL_MAKEFILE_DEPENDS dlls/wbemprox/Makefile: dlls/wbemprox/Makefile.in dlls/Makedll.rules" ac_config_files="$ac_config_files dlls/wbemprox/Makefile" +ALL_MAKEFILES="$ALL_MAKEFILES \\ + dlls/wiaservc/Makefile" +test "x$enable_wiaservc" != xno && ALL_DLL_DIRS="$ALL_DLL_DIRS \\ + wiaservc" +ALL_MAKEFILE_DEPENDS="$ALL_MAKEFILE_DEPENDS +dlls/wiaservc/Makefile: dlls/wiaservc/Makefile.in dlls/Makedll.rules" +ac_config_files="$ac_config_files dlls/wiaservc/Makefile" + ALL_MAKEFILES="$ALL_MAKEFILES \\ dlls/win32s16.dll16/Makefile" test "x$enable_win16" != xno && ALL_DLL_DIRS="$ALL_DLL_DIRS \\ @@ -19154,6 +19162,7 @@ do "dlls/w32skrnl/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/w32skrnl/Makefile" ;; "dlls/w32sys.dll16/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/w32sys.dll16/Makefile" ;; "dlls/wbemprox/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/wbemprox/Makefile" ;; + "dlls/wiaservc/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/wiaservc/Makefile" ;; "dlls/win32s16.dll16/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/win32s16.dll16/Makefile" ;; "dlls/win87em.dll16/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/win87em.dll16/Makefile" ;; "dlls/winaspi.dll16/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/winaspi.dll16/Makefile" ;; diff --git a/configure.ac b/configure.ac index f6ac8936726..0974b2794a1 100644 --- a/configure.ac +++ b/configure.ac @@ -2506,6 +2506,7 @@ WINE_CONFIG_MAKEFILE([dlls/vwin32.vxd/Makefile],[dlls/Makedll.rules],[dlls],[ALL WINE_CONFIG_MAKEFILE([dlls/w32skrnl/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) WINE_CONFIG_MAKEFILE([dlls/w32sys.dll16/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS],[enable_win16]) WINE_CONFIG_MAKEFILE([dlls/wbemprox/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) +WINE_CONFIG_MAKEFILE([dlls/wiaservc/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS]) WINE_CONFIG_MAKEFILE([dlls/win32s16.dll16/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS],[enable_win16]) WINE_CONFIG_MAKEFILE([dlls/win87em.dll16/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS],[enable_win16]) WINE_CONFIG_MAKEFILE([dlls/winaspi.dll16/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS],[enable_win16]) diff --git a/dlls/wiaservc/Makefile.in b/dlls/wiaservc/Makefile.in new file mode 100644 index 00000000000..8fbffd03988 --- /dev/null +++ b/dlls/wiaservc/Makefile.in @@ -0,0 +1,14 @@ +TOPSRCDIR = @top_srcdir@ +TOPOBJDIR = ../.. +SRCDIR = @srcdir@ +VPATH = @srcdir@ +MODULE = wiaservc.dll +IMPORTS = uuid ole32 advapi32 kernel32 + +C_SRCS = \ + service.c \ + wiaservc_main.c + +@MAKE_DLL_RULES@ + +@DEPENDENCIES@ # everything below this line is overwritten by make depend diff --git a/dlls/wiaservc/service.c b/dlls/wiaservc/service.c new file mode 100644 index 00000000000..4e91c41880e --- /dev/null +++ b/dlls/wiaservc/service.c @@ -0,0 +1,142 @@ +/* + * ServiceMain function for wiaservc running within svchost + * + * Copyright 2009 Damjan Jovanovic + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "windef.h" +#include "objbase.h" +#include "winsvc.h" +#include "wia.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wia); + +static HANDLE stop_event = NULL; + +static SERVICE_STATUS_HANDLE status_handle; +static SERVICE_STATUS status; +static DWORD dwReg; + +static VOID +UpdateStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint) +{ + status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; + status.dwCurrentState = dwCurrentState; + if (dwCurrentState == SERVICE_START_PENDING) + status.dwControlsAccepted = 0; + else + status.dwControlsAccepted + = (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE + | SERVICE_ACCEPT_SHUTDOWN); + status.dwWin32ExitCode = 0; + status.dwServiceSpecificExitCode = 0; + status.dwCheckPoint = 0; + status.dwWaitHint = dwWaitHint; + + if (!SetServiceStatus(status_handle, &status)) { + ERR("failed to set service status\n"); + SetEvent(stop_event); + } +} + +/* Handle incoming ControlService signals */ +static DWORD WINAPI +ServiceHandler(DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context) +{ + switch (ctrl) { + case SERVICE_CONTROL_STOP: + case SERVICE_CONTROL_SHUTDOWN: + TRACE("shutting down service\n"); + UpdateStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); + SetEvent(stop_event); + break; + default: + FIXME("ignoring handle service ctrl %x\n", ctrl); + UpdateStatus(status.dwCurrentState, NO_ERROR, 0); + break; + } + + return NO_ERROR; +} + +static BOOL +StartCount(void) +{ + HRESULT hr; + + TRACE("\n"); + + hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + if (FAILED(hr)) + return FALSE; + + hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, + RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, + NULL); + if (FAILED(hr)) + return FALSE; + +/* FIXME: implement + hr = CoRegisterClassObject(&CLSID_WiaDevMgr, + (IUnknown *) &WIASERVC_ClassFactory, + CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, + &dwReg); + if (FAILED(hr)) + return FALSE; + */ + return TRUE; +} + +/* Service entry point */ +VOID WINAPI +ServiceMain(DWORD dwArgc, LPWSTR *lpszArgv) +{ + static const WCHAR stisvc_nameW[] = {'s','t','i','s','v','c',0}; + TRACE("(%d, %p)\n", dwArgc, lpszArgv); + + stop_event = CreateEventW(NULL, TRUE, FALSE, NULL); + if (!stop_event) { + ERR("failed to create stop_event\n"); + return; + } + + status_handle = RegisterServiceCtrlHandlerExW(stisvc_nameW, ServiceHandler, NULL); + if (!status_handle) { + ERR("failed to register handler: %u\n", GetLastError()); + return; + } + + UpdateStatus(SERVICE_START_PENDING, NO_ERROR, 3000); + if (!StartCount()) { + ERR("failed starting service thread\n"); + UpdateStatus(SERVICE_STOPPED, NO_ERROR, 0); + return; + } + + UpdateStatus(SERVICE_RUNNING, NO_ERROR, 0); + + WaitForSingleObject(stop_event, INFINITE); + + CoRevokeClassObject(dwReg); + UpdateStatus(SERVICE_STOPPED, NO_ERROR, 0); + CloseHandle(stop_event); + TRACE("service stopped\n"); + + CoUninitialize(); +} diff --git a/dlls/wiaservc/wiaservc.spec b/dlls/wiaservc/wiaservc.spec new file mode 100644 index 00000000000..afd2426cc31 --- /dev/null +++ b/dlls/wiaservc/wiaservc.spec @@ -0,0 +1,57 @@ +@ stdcall -private ServiceMain(long ptr) +@ stub DllRegisterServer +@ stub DllUnregisterServer +@ stub wiasCreateChildAppItem +@ stub wiasCreateDrvItem +@ stub wiasCreateLogInstance +@ stub wiasCreatePropContext +@ stub wiasDebugError +@ stub wiasDebugTrace +@ stub wiasDownSampleBuffer +@ stub wiasFormatArgs +@ stub wiasFreePropContext +@ stub wiasGetChangedValueFloat +@ stub wiasGetChangedValueGuid +@ stub wiasGetChangedValueLong +@ stub wiasGetChangedValueStr +@ stub wiasGetChildrenContexts +@ stub wiasGetContextFromName +@ stub wiasGetDrvItem +@ stub wiasGetImageInformation +@ stub wiasGetItemType +@ stub wiasGetPropertyAttributes +@ stub wiasGetRootItem +@ stub wiasIsPropChanged +@ stub wiasParseEndorserString +@ stub wiasPrintDebugHResult +@ stub wiasQueueEvent +@ stub wiasReadMultiple +@ stub wiasReadPropBin +@ stub wiasReadPropFloat +@ stub wiasReadPropGuid +@ stub wiasReadPropLong +@ stub wiasReadPropStr +@ stub wiasSendEndOfPage +@ stub wiasSetItemPropAttribs +@ stub wiasSetItemPropNames +@ stub wiasSetPropChanged +@ stub wiasSetPropertyAttributes +@ stub wiasSetValidFlag +@ stub wiasSetValidListFloat +@ stub wiasSetValidListGuid +@ stub wiasSetValidListLong +@ stub wiasSetValidListStr +@ stub wiasSetValidRangeFloat +@ stub wiasSetValidRangeLong +@ stub wiasUpdateScanRect +@ stub wiasUpdateValidFormat +@ stub wiasValidateItemProperties +@ stub wiasWriteBufToFile +@ stub wiasWriteMultiple +@ stub wiasWritePageBufToFile +@ stub wiasWritePageBufToStream +@ stub wiasWritePropBin +@ stub wiasWritePropFloat +@ stub wiasWritePropGuid +@ stub wiasWritePropLong +@ stub wiasWritePropStr diff --git a/dlls/wiaservc/wiaservc_main.c b/dlls/wiaservc/wiaservc_main.c new file mode 100644 index 00000000000..4f9427534b6 --- /dev/null +++ b/dlls/wiaservc/wiaservc_main.c @@ -0,0 +1,56 @@ +/* + * Main DLL interface to WIA Device Manager + * + * Copyright 2009 Damjan Jovanovic + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "objbase.h" +#include "winuser.h" +#include "winreg.h" +#include "advpub.h" +#include "olectl.h" +#include "winsvc.h" + +#include "wia.h" +#include "initguid.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wia); + +/* Handle to the base address of this DLL */ +static HINSTANCE hInst; + +/* Entry point for DLL */ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved); + + switch (fdwReason) + { + case DLL_WINE_PREATTACH: + return FALSE; /* prefer native version */ + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hinstDLL); + hInst = hinstDLL; + break; + case DLL_PROCESS_DETACH: + break; + } + + return TRUE; +}