From a341a967893555f93d04dfb442ae4767b36a94b6 Mon Sep 17 00:00:00 2001
From: Mike McCormack <mike_mccormack@looksmart.com.au>
Date: Sat, 15 Jul 2000 21:36:31 +0000
Subject: [PATCH] Hook serialui dll into existing comm functions.

---
 dlls/kernel/kernel32.spec |  12 +-
 misc/comm.c               | 229 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 232 insertions(+), 9 deletions(-)

diff --git a/dlls/kernel/kernel32.spec b/dlls/kernel/kernel32.spec
index 8f6108a4762..6799d1fb3b8 100644
--- a/dlls/kernel/kernel32.spec
+++ b/dlls/kernel/kernel32.spec
@@ -156,8 +156,8 @@ import  ntdll.dll
 137 stdcall CloseHandle(long) CloseHandle
 138 stdcall CloseProfileUserMapping() CloseProfileUserMapping
 139 stub CloseSystemHandle
-140 stub CommConfigDialogA
-141 stub CommConfigDialogW
+140 stdcall CommConfigDialogA(str long ptr) CommConfigDialogA
+141 stdcall CommConfigDialogW(wstr long ptr) CommConfigDialogW
 142 stdcall CompareFileTime(ptr ptr) CompareFileTime
 143 stdcall CompareStringA(long long str long str long) CompareStringA
 144 stdcall CompareStringW(long long wstr long wstr long) CompareStringW
@@ -299,7 +299,7 @@ import  ntdll.dll
 280 stdcall GetBinaryTypeA(ptr ptr) GetBinaryTypeA
 281 stdcall GetBinaryTypeW(ptr ptr) GetBinaryTypeW
 282 stdcall GetCPInfo(long ptr) GetCPInfo
-283 stub GetCommConfig
+283 stdcall GetCommConfig(long ptr) GetCommConfig
 284 stdcall GetCommMask(long ptr) GetCommMask
 285 stdcall GetCommModemStatus(long ptr) GetCommModemStatus
 286 stdcall GetCommProperties(long ptr) GetCommProperties
@@ -633,7 +633,7 @@ import  ntdll.dll
 614 stdcall SearchPathA(str str str long ptr ptr) SearchPathA
 615 stdcall SearchPathW(wstr wstr wstr long ptr ptr) SearchPathW
 616 stdcall SetCommBreak(long) SetCommBreak
-617 stub SetCommConfig
+617 stdcall SetCommConfig(long ptr) SetCommConfig
 618 stdcall SetCommMask(long ptr) SetCommMask
 619 stdcall SetCommState(long ptr) SetCommState
 620 stdcall SetCommTimeouts(long ptr) SetCommTimeouts
@@ -654,8 +654,8 @@ import  ntdll.dll
 635 stdcall SetCurrentDirectoryA(str) SetCurrentDirectoryA
 636 stdcall SetCurrentDirectoryW(wstr) SetCurrentDirectoryW
 637 stub SetDaylightFlag
-638 stub SetDefaultCommConfigA
-639 stub SetDefaultCommConfigW
+638 stdcall SetDefaultCommConfigA(str ptr long) SetDefaultCommConfigA
+639 stdcall SetDefaultCommConfigW(wstr ptr long) SetDefaultCommConfigW
 640 stdcall SetEndOfFile(long) SetEndOfFile
 641 stdcall SetEnvironmentVariableA(str str) SetEnvironmentVariableA
 642 stdcall SetEnvironmentVariableW(wstr wstr) SetEnvironmentVariableW
diff --git a/misc/comm.c b/misc/comm.c
index 4df8fce18e1..be010193363 100644
--- a/misc/comm.c
+++ b/misc/comm.c
@@ -2581,14 +2581,237 @@ BOOL WINAPI WaitCommEvent(HANDLE hFile,LPDWORD eventmask ,LPOVERLAPPED overlappe
 }
 
 /***********************************************************************
- *           GetCommProperties   (KERNEL32.???)
+ *           GetCommProperties   (KERNEL32.286)
+ *
+ * This function fills in a structure with the capabilities of the 
+ * communications port driver.
+ *
+ * RETURNS
+ *
+ *  TRUE on success, FALSE on failure
+ *  If successful, the lpCommProp structure be filled in with
+ *  properties of the comm port.
  */
-BOOL WINAPI GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
-{
+BOOL WINAPI GetCommProperties(
+	HANDLE hFile,          /* handle of the comm port */
+	LPCOMMPROP lpCommProp /* pointer to struct to be filled */
+) {
     FIXME("(%d %p )\n",hFile,lpCommProp);
+    if(!lpCommProp)
+        return FALSE;
+
+    /*
+     * These values should be valid for LINUX's serial driver
+     * FIXME: Perhaps they deserve an #ifdef LINUX
+     */
+    memset(lpCommProp,0,sizeof(COMMPROP));
+    lpCommProp->wPacketLength       = 1;
+    lpCommProp->wPacketVersion      = 1;
+    lpCommProp->dwServiceMask       = SP_SERIALCOMM;
+    lpCommProp->dwReserved1         = 0;
+    lpCommProp->dwMaxTxQueue        = 4096;
+    lpCommProp->dwMaxRxQueue        = 4096;
+    lpCommProp->dwMaxBaud           = BAUD_115200;
+    lpCommProp->dwProvSubType       = PST_RS232;
+    lpCommProp->dwProvCapabilities  = PCF_DTRDSR | PCF_PARITY_CHECK | PCF_RTSCTS ;
+    lpCommProp->dwSettableParams    = SP_BAUD | SP_DATABITS | SP_HANDSHAKING | 
+                                      SP_PARITY | SP_PARITY_CHECK | SP_STOPBITS ;
+    lpCommProp->dwSettableBaud      = BAUD_075 | BAUD_110 | BAUD_134_5 | BAUD_150 |
+                BAUD_300 | BAUD_600 | BAUD_1200 | BAUD_1800 | BAUD_2400 | BAUD_4800 |
+                BAUD_9600 | BAUD_19200 | BAUD_38400 | BAUD_57600 | BAUD_115200 ;
+    lpCommProp->wSettableData       = DATABITS_5 | DATABITS_6 | DATABITS_7 | DATABITS_8 ;
+    lpCommProp->wSettableStopParity = STOPBITS_10 | STOPBITS_15 | STOPBITS_20 | 
+                PARITY_NONE | PARITY_ODD |PARITY_EVEN | PARITY_MARK | PARITY_SPACE;
+    lpCommProp->dwCurrentTxQueue    = lpCommProp->dwMaxTxQueue;
+    lpCommProp->dwCurrentRxQueue    = lpCommProp->dwMaxRxQueue;
+
     return TRUE;
 }
 
+/***********************************************************************
+ * FIXME:
+ * The functionality of CommConfigDialogA, GetDefaultCommConfig and
+ * SetDefaultCommConfig is implemented in a DLL (usually SERIALUI.DLL).
+ * This is dependent on the type of COMM port, but since it is doubtful
+ * anybody will get around to implementing support for fancy serial
+ * ports in WINE, this is hardcoded for the time being.  The name of 
+ * this DLL should be stored in and read from the system registry in 
+ * the hive HKEY_LOCAL_MACHINE, key
+ * System\\CurrentControlSet\\Services\\Class\\Ports\\????
+ * where ???? is the port number... that is determined by PNP
+ * The DLL should be loaded when the COMM port is opened, and closed 
+ * when the COMM port is closed. - MJM 20 June 2000
+ ***********************************************************************/
+static CHAR lpszSerialUI[] = "serialui.dll";
+
+
+/***********************************************************************
+ *           CommConfigDialogA   (KERNEL32.140)
+ *
+ * Raises a dialog that allows the user to configure a comm port.
+ * Fills the COMMCONFIG struct with information specified by the user.
+ * This function should call a similar routine in the COMM driver...
+ *
+ * RETURNS
+ *
+ *  TRUE on success, FALSE on failure
+ *  If successful, the lpCommConfig structure will contain a new
+ *  configuration for the comm port, as specified by the user.
+ *
+ * BUGS
+ *  The library with the CommConfigDialog code is never unloaded.
+ * Perhaps this should be done when the comm port is closed?
+ */
+BOOL WINAPI CommConfigDialogA(
+	LPCSTR lpszDevice,         /* name of communications device */
+	HANDLE hWnd,               /* parent window for the dialog */
+	LPCOMMCONFIG lpCommConfig  /* pointer to struct to fill */
+) {
+    FARPROC lpfnCommDialog;
+    HMODULE hConfigModule;
+    BOOL r;
+
+    TRACE("(%p %x %p)\n",lpszDevice, hWnd, lpCommConfig);
+
+    hConfigModule = LoadLibraryA(lpszSerialUI);
+    if(!hConfigModule)
+        return FALSE;
+
+    lpfnCommDialog = GetProcAddress(hConfigModule, (LPCSTR)3L);
+
+    if(!lpfnCommDialog)
+        return FALSE;
+
+    r = lpfnCommDialog(lpszDevice,hWnd,lpCommConfig);
+
+    /* UnloadLibrary(hConfigModule); */
+
+    return r;
+}
+
+/***********************************************************************
+ *           CommConfigDialogW   (KERNEL32.141)
+ *
+ * see CommConfigDialogA for more info
+ */
+BOOL WINAPI CommConfigDialogW(
+	LPCWSTR lpszDevice,        /* name of communications device */
+	HANDLE hWnd,               /* parent window for the dialog */
+	LPCOMMCONFIG lpCommConfig  /* pointer to struct to fill */
+) {
+    BOOL r;
+    LPSTR lpDeviceA;
+
+    lpDeviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice );
+    if(lpDeviceA)
+        return FALSE;
+    r = CommConfigDialogA(lpDeviceA,hWnd,lpCommConfig);
+    HeapFree( GetProcessHeap(), 0, lpDeviceA );
+    return r;
+}
+
+/***********************************************************************
+ *           GetCommConfig     (KERNEL32.283)
+ *
+ * Fill in the COMMCONFIG structure for the comm port hFile
+ *
+ * RETURNS
+ *
+ *  TRUE on success, FALSE on failure
+ *  If successful, lpCommConfig contains the comm port configuration.
+ */
+BOOL WINAPI GetCommConfig(
+	HFILE hFile,
+	LPCOMMCONFIG lpCommConfig
+) {
+    BOOL r;
+
+    TRACE("(%x %p)\n",hFile,lpCommConfig);
+
+    if(lpCommConfig == NULL)
+        return FALSE;
+
+    lpCommConfig->dwSize = sizeof(COMMCONFIG);
+    lpCommConfig->wVersion = 1;
+    lpCommConfig->wReserved = 0;
+    r = GetCommState(hFile,&lpCommConfig->dcb);
+    lpCommConfig->dwProviderSubType = PST_RS232;
+    lpCommConfig->dwProviderOffset = 0;
+    lpCommConfig->dwProviderSize = 0;
+
+    return r;
+}
+
+/***********************************************************************
+ *           SetCommConfig     (KERNEL32.617)
+ *
+ */
+BOOL WINAPI SetCommConfig(
+	HFILE hFile,
+	LPCOMMCONFIG lpCommConfig
+) {
+    BOOL r;
+
+    TRACE("(%x %p)\n",hFile,lpCommConfig);
+    
+    r = SetCommState(hFile,&lpCommConfig->dcb);
+    return r;
+}
+
+/***********************************************************************
+ *           GetCommProperties   (KERNEL32.286)
+ */
+BOOL WINAPI SetDefaultCommConfigA(
+	LPCSTR lpszDevice, 
+	LPCOMMCONFIG lpCommConfig,
+	DWORD dwSize
+) {
+    FARPROC lpfnSetDefaultCommConfig;
+    HMODULE hConfigModule;
+    BOOL r;
+
+    TRACE("(%p %p %lx)\n",lpszDevice, lpCommConfig, dwSize);
+
+    hConfigModule = LoadLibraryA(lpszSerialUI);
+    if(!hConfigModule)
+        return FALSE;
+
+    lpfnSetDefaultCommConfig = GetProcAddress(hConfigModule, (LPCSTR)4L);
+
+    if(! lpfnSetDefaultCommConfig)
+	return TRUE;
+
+    r = lpfnSetDefaultCommConfig(lpszDevice, lpCommConfig, dwSize);
+
+    /* UnloadLibrary(hConfigModule); */
+
+    return r;
+}
+
+
+/***********************************************************************
+ *           SetDefaultCommConfigW     (KERNEL32.639)
+ *
+ */
+BOOL WINAPI SetDefaultCommConfigW(
+	LPCWSTR lpszDevice, 
+	LPCOMMCONFIG lpCommConfig,
+	DWORD dwSize
+) {
+    BOOL r;
+    LPSTR lpDeviceA;
+
+    TRACE("(%s %p %lx)\n",debugstr_w(lpszDevice),lpCommConfig,dwSize);
+
+    lpDeviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice );
+    if(lpDeviceA)
+        return FALSE;
+    r = SetDefaultCommConfigA(lpDeviceA,lpCommConfig,dwSize);
+    HeapFree( GetProcessHeap(), 0, lpDeviceA );
+    return r;
+}
+
+
 /***********************************************************************
  *           GetDefaultCommConfigA   (KERNEL32.313)
  */
-- 
GitLab