[Wine-patches] wineusb: Load USB device drivers when it is necessary.
Alexander Morozov
=?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Окт 27 19:46:00 MSK 2008
Чтобы драйвер не загружался при загрузке wine даже когда нет USB-устройства,
надо изменить HKLM\System\CurrentControlSet\Services\имя_драйвера\Start на 3
(SERVICE_DEMAND_START).
dwCurrentState устанавливается в SERVICE_RUNNING, так как иначе StartServiceW
завершается с ошибкой ERROR_SERVICE_DATABASE_LOCKED.
----------- следующая часть -----------
From 2a1c5004a9bf1d89cdc4f1fbb63d6a7d9206c30d Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Mon, 27 Oct 2008 19:32:09 +0300
Subject: [PATCH] wineusb: Load USB device drivers when it is necessary.
---
programs/wineusb/main.c | 38 ++++++++++++++++++++++++++++++++++++--
1 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/programs/wineusb/main.c b/programs/wineusb/main.c
index 24d0690..51fcd3c 100644
--- a/programs/wineusb/main.c
+++ b/programs/wineusb/main.c
@@ -59,6 +59,32 @@ struct DeviceInstance
struct usb_device *dev;
};
+static BOOL start_service( PWSTR name )
+{
+ SC_HANDLE scm, service;
+ BOOL ret;
+
+ scm = OpenSCManagerA( NULL, NULL, SC_MANAGER_ALL_ACCESS );
+ if (scm == NULL)
+ return FALSE;
+
+ service = OpenServiceW( scm, name, SERVICE_ALL_ACCESS );
+ if (service == NULL)
+ {
+ CloseServiceHandle( scm );
+ return FALSE;
+ }
+
+ ret = StartServiceW( service, 0, NULL );
+ if (!ret && ERROR_SERVICE_ALREADY_RUNNING == GetLastError())
+ ret = TRUE;
+
+ CloseServiceHandle( service );
+ CloseServiceHandle( scm );
+
+ return ret;
+}
+
static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
{
SERVICE_STATUS status;
@@ -104,7 +130,7 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
return;
status.dwServiceType = SERVICE_WIN32;
- status.dwCurrentState = SERVICE_START_PENDING;
+ status.dwCurrentState = SERVICE_RUNNING;
status.dwControlsAccepted = 0;
status.dwWin32ExitCode = 0;
status.dwServiceSpecificExitCode = 0;
@@ -211,7 +237,15 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
HeapFree( GetProcessHeap(), 0, buf );
break;
}
- /* FIXME: check if driver is loaded */
+
+ if (!start_service( (PWSTR)buf ))
+ {
+ HeapFree( GetProcessHeap(), 0, buf );
+ HeapFree( GetProcessHeap(), 0, instance );
+ ret = FALSE;
+ break;
+ }
+
RtlInitUnicodeString( &drvname, (PWSTR)buf );
strcpy( (char *)(pdo_info + 1), bus->dirname );
strcpy( (char *)(pdo_info + 2 + strlen( bus->dirname )), dev->filename );
--
1.5.6.5.GIT
Подробная информация о списке рассылки Wine-patches