WINSPOOL: fix port enumeration
Mike McCormack
mike at codeweavers.com
Sun Oct 3 04:50:41 CDT 2004
Following the filesystem rewrite, the method of specifying COM ports has
changed. When enumerating COM ports, try to open COM[1234] instead of
looking them up in the config file.
Mike
ChangeLog:
* fix port enumeration
-------------- next part --------------
Index: dlls/winspool/info.c
===================================================================
RCS file: /home/wine/wine/dlls/winspool/info.c,v
retrieving revision 1.93
diff -u -r1.93 info.c
--- dlls/winspool/info.c 2 May 2004 04:21:16 -0000 1.93
+++ dlls/winspool/info.c 3 Oct 2004 09:34:38 -0000
@@ -3002,6 +3002,35 @@
static CHAR PortMonitor[] = "Wine Port Monitor";
static CHAR PortDescription[] = "Wine Port";
+static BOOL WINSPOOL_ComPortExists( LPCSTR name )
+{
+ HANDLE handle;
+
+ handle = CreateFileA( name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, 0, NULL );
+ if (handle == INVALID_HANDLE_VALUE)
+ return FALSE;
+ ERR("Checking %s exists\n", name );
+ CloseHandle( handle );
+ return TRUE;
+}
+
+static DWORD WINSPOOL_CountSerialPorts()
+{
+ CHAR name[6];
+ DWORD n = 0, i;
+
+ for (i=0; i<4; i++)
+ {
+ strcpy( name, "COMx:" );
+ name[3] = '1' + i;
+ if (WINSPOOL_ComPortExists( name ))
+ n++;
+ }
+
+ return n;
+}
+
/******************************************************************************
* EnumPortsA (WINSPOOL.@)
*/
@@ -3010,9 +3039,8 @@
{
CHAR portname[10];
DWORD info_size, ofs, i, printer_count, serial_count, count, n, r;
- const LPCSTR szSerialPortKey = "Software\\Wine\\Wine\\Config\\serialports";
const LPCSTR szPrinterPortKey = "Software\\Wine\\Wine\\Config\\spooler";
- HKEY hkey_serial, hkey_printer;
+ HKEY hkey_printer;
TRACE("(%s,%ld,%p,%ld,%p,%p)\n",
name,level,buffer,bufsize,bufneeded,bufreturned);
@@ -3032,16 +3060,9 @@
/* see how many exist */
- hkey_serial = 0;
hkey_printer = 0;
- serial_count = 0;
+ serial_count = WINSPOOL_CountSerialPorts();
printer_count = 0;
- r = RegOpenKeyA( HKEY_LOCAL_MACHINE, szSerialPortKey, &hkey_serial);
- if (r == ERROR_SUCCESS)
- {
- RegQueryInfoKeyA ( hkey_serial, NULL, NULL, NULL, NULL, NULL, NULL,
- &serial_count, NULL, NULL, NULL, NULL);
- }
r = RegOpenKeyA( HKEY_LOCAL_MACHINE, szPrinterPortKey, &hkey_printer);
if ( r == ERROR_SUCCESS )
@@ -3063,14 +3084,22 @@
/* get the serial port values, then the printer values */
if ( i < serial_count )
- r = RegEnumValueA( hkey_serial, i,
- portname, &vallen, NULL, NULL, NULL, 0 );
+ {
+ strcpy( portname, "COMx:" );
+ portname[3] = '1' + i;
+ if (!WINSPOOL_ComPortExists( portname ))
+ continue;
+
+ ERR("Found %s\n", portname );
+ vallen = strlen( portname );
+ }
else
+ {
r = RegEnumValueA( hkey_printer, i-serial_count,
portname, &vallen, NULL, NULL, NULL, 0 );
-
- if ( r )
- continue;
+ if ( r )
+ continue;
+ }
/* add a colon if necessary, and make it upper case */
CharUpperBuffA(portname,vallen);
@@ -3105,7 +3134,6 @@
n++;
}
- RegCloseKey(hkey_serial);
RegCloseKey(hkey_printer);
if(bufneeded)
More information about the wine-patches
mailing list