winedevice: eliminate the driver_name global variable
Damjan Jovanovic
damjan.jov at gmail.com
Thu Jun 30 23:38:00 CDT 2011
Changelog:
* winedevice: eliminate the driver_name global variable
This is part of general refactoring to make the driver loading code reusable.
Damjan Jovanovic
-------------- next part --------------
diff --git a/programs/winedevice/device.c b/programs/winedevice/device.c
index 2ce8c15..f8d6d2f 100644
--- a/programs/winedevice/device.c
+++ b/programs/winedevice/device.c
@@ -40,7 +40,6 @@ WINE_DECLARE_DEBUG_CHANNEL(relay);
extern NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event );
-static WCHAR *driver_name;
static SERVICE_STATUS_HANDLE service_handle;
static HKEY driver_hkey;
static HANDLE stop_event;
@@ -130,7 +129,7 @@ error:
}
/* call the driver init entry point */
-static NTSTATUS init_driver( HMODULE module, UNICODE_STRING *keyname )
+static NTSTATUS init_driver( WCHAR *driver_name, HMODULE module, UNICODE_STRING *keyname )
{
unsigned int i;
NTSTATUS status;
@@ -167,7 +166,7 @@ static NTSTATUS init_driver( HMODULE module, UNICODE_STRING *keyname )
}
/* load the .sys module for a device driver */
-static BOOL load_driver(void)
+static BOOL load_driver(WCHAR* driver_name)
{
static const WCHAR driversW[] = {'\\','d','r','i','v','e','r','s','\\',0};
static const WCHAR postfixW[] = {'.','s','y','s',0};
@@ -234,13 +233,14 @@ static BOOL load_driver(void)
HeapFree( GetProcessHeap(), 0, path );
if (!module) return FALSE;
- init_driver( module, &keypath );
+ init_driver( driver_name, module, &keypath );
return TRUE;
}
static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
{
SERVICE_STATUS status;
+ WCHAR *driver_name = (WCHAR*)context;
status.dwServiceType = SERVICE_WIN32;
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
@@ -270,12 +270,13 @@ static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_
static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
{
SERVICE_STATUS status;
+ WCHAR *driver_name = argv[0];
WINE_TRACE( "starting service %s\n", wine_dbgstr_w(driver_name) );
stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
- service_handle = RegisterServiceCtrlHandlerExW( driver_name, service_handler, NULL );
+ service_handle = RegisterServiceCtrlHandlerExW( driver_name, service_handler, driver_name );
if (!service_handle)
return;
@@ -288,7 +289,7 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
status.dwWaitHint = 10000;
SetServiceStatus( service_handle, &status );
- if (load_driver())
+ if (load_driver(driver_name))
{
status.dwCurrentState = SERVICE_RUNNING;
status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
@@ -308,7 +309,7 @@ int wmain( int argc, WCHAR *argv[] )
{
SERVICE_TABLE_ENTRYW service_table[2];
- if (!(driver_name = argv[1]))
+ if (!argv[1])
{
WINE_ERR( "missing device name, winedevice isn't supposed to be run manually\n" );
return 1;
More information about the wine-patches
mailing list