localspl: [2/3] Implement XcvData_AddPort (updated)

Detlef Riekenberg wine.dev at web.de
Tue Apr 17 16:20:34 CDT 2007


Native localui.dll call this API.
Our localui will do the same.


Changelog:
localspl: Implement XcvData_AddPort


spoolss.dll is now imported, as requested by Alexandre


-- 
 
By by ... Detlef

-------------- next part --------------
>From 2414d9104f65a877e18c1f5498422ef0888c0f12 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Tue, 17 Apr 2007 22:00:43 +0200
Subject: [PATCH] localspl: Implement XcvData_AddPort
---
 dlls/localspl/Makefile.in |    2 +-
 dlls/localspl/localmon.c  |   58 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/dlls/localspl/Makefile.in b/dlls/localspl/Makefile.in
index 06830de..3fdd790 100644
--- a/dlls/localspl/Makefile.in
+++ b/dlls/localspl/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = localspl.dll
-IMPORTS   = user32 advapi32 kernel32
+IMPORTS   = user32 advapi32 kernel32 spoolss
 
 C_SRCS = \
 	localmon.c \
diff --git a/dlls/localspl/localmon.c b/dlls/localspl/localmon.c
index 7e13ace..5840313 100644
--- a/dlls/localspl/localmon.c
+++ b/dlls/localspl/localmon.c
@@ -65,6 +65,7 @@ static struct list xcv_handles = LIST_IN
 
 /* ############################### */
 
+static const WCHAR cmd_AddPortW[] = {'A','d','d','P','o','r','t',0};
 static const WCHAR cmd_DeletePortW[] = {'D','e','l','e','t','e','P','o','r','t',0};
 static const WCHAR cmd_ConfigureLPTPortCommandOKW[] = {'C','o','n','f','i','g','u','r','e',
                                     'L','P','T','P','o','r','t',
@@ -85,6 +86,7 @@ static const WCHAR cmd_SetDefaultCommCon
                                     'C','o','m','m','C','o','n','f','i','g',0};
 
 static const WCHAR dllnameuiW[] = {'l','o','c','a','l','u','i','.','d','l','l',0};
+static const WCHAR emptyW[] = {0};
 
 static const WCHAR portname_LPT[]  = {'L','P','T',0};
 static const WCHAR portname_COM[]  = {'C','O','M',0};
@@ -126,6 +128,44 @@ static void dlg_nothingtoconfig(HWND hWn
 }
 
 /******************************************************************
+ * does_port_exist (internal)  
+ *
+ * returns TRUE, when the Port already exists
+ * 
+ */
+BOOL does_port_exist(LPCWSTR myname)
+{
+
+    LPPORT_INFO_1W  pi;
+    DWORD   needed = 0;
+    DWORD   returned;
+    DWORD   id;
+
+    TRACE("(%s)\n", debugstr_w(myname));
+
+    id = EnumPortsW(NULL, 1, NULL, 0, &needed, &returned);
+    pi = spl_alloc(needed);
+    returned = 0;
+    if (pi)
+        id = EnumPortsW(NULL, 1, (LPBYTE) pi, needed, &needed, &returned); 
+
+    if (id && returned > 0) {
+        /* we got a number of valid names. */
+        for (id = 0; id < returned; id++)
+        {
+            if (lstrcmpiW(myname, pi[id].pName) == 0) {
+                TRACE("(%u) found %s\n", id, debugstr_w(pi[id].pName));
+                spl_free(pi);
+                return TRUE;
+            }
+        }
+    }
+
+    spl_free(pi);
+    return FALSE;
+}
+
+/******************************************************************
  * enumerate the local Ports from the Registry (internal)  
  *
  * See localmon_EnumPortsW.
@@ -459,8 +499,22 @@ DWORD WINAPI localmon_XcvDataPort(HANDLE
     TRACE("(%p, %s, %p, %d, %p, %d, %p)\n", hXcv, debugstr_w(pszDataName),
           pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
 
-    /* Native localspl.dll crashes on w2k and xp, when XcvDataPort is called
-       with "AddPort" as command. We do not need to implement this */
+    if (!lstrcmpW(pszDataName, cmd_AddPortW)) {
+        TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
+        res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot);
+        if (res == ERROR_SUCCESS) {
+            if (does_port_exist((LPWSTR) pInputData)) {
+                RegCloseKey(hroot);
+                return ERROR_ALREADY_EXISTS;
+            }
+            res = RegSetValueExW(hroot, (LPWSTR) pInputData, 0, REG_SZ, (const BYTE *) emptyW, sizeof(emptyW));
+            RegCloseKey(hroot);
+            SetLastError(ERROR_SUCCESS);
+            return res;
+        }
+        return res;
+    }
+
 
     if (!lstrcmpW(pszDataName, cmd_ConfigureLPTPortCommandOKW)) {
         TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
-- 
1.4.1



More information about the wine-patches mailing list