localspl: Implement AddPortEx

Detlef Riekenberg wine.dev at web.de
Wed Jun 13 18:08:03 CDT 2007


localspl: Implement AddPortEx

After this Patch, we can always create and delete Ports
(non interactive) for more complex tests.

 

-- 
 
By by ... Detlef

-------------- next part --------------
>From e163aab599facacfd8a47a61c361d3bf0f2ccd61 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Thu, 14 Jun 2007 01:01:11 +0200
Subject: [PATCH] localspl: Implement AddPortExW
---
 dlls/localspl/localmon.c |   62 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/dlls/localspl/localmon.c b/dlls/localspl/localmon.c
index 57cdd7a..3d48b66 100644
--- a/dlls/localspl/localmon.c
+++ b/dlls/localspl/localmon.c
@@ -85,6 +85,7 @@ static const WCHAR cmd_SetDefaultCommCon
 
 static const WCHAR dllnameuiW[] = {'l','o','c','a','l','u','i','.','d','l','l',0};
 static const WCHAR emptyW[] = {0};
+static const WCHAR LocalPortW[] = {'L','o','c','a','l',' ','P','o','r','t',0};
 
 static const WCHAR portname_LPT[]  = {'L','P','T',0};
 static const WCHAR portname_COM[]  = {'C','O','M',0};
@@ -298,6 +299,63 @@ static DWORD get_type_from_name(LPCWSTR 
     return PORT_IS_UNKNOWN;
 }
 
+/******************************************************************************
+ *   localmon_AddPortExW [exported through MONITOREX]
+ *
+ * Add a Port, without presenting a user interface
+ *
+ * PARAMS
+ *  pName         [I] Servername or NULL (local Computer)
+ *  level         [I] Structure-Level (1) for pBuffer
+ *  pBuffer       [I] PTR to the Input-Data (PORT_INFO_1)
+ *  pMonitorName  [I] Name of the Monitor that manage the Port
+ *
+ * RETURNS
+ *  Success: TRUE
+ *  Failure: FALSE
+ *
+ * NOTES
+ *  Level 2 is documented on MSDN for Portmonitors, but not supported by the
+ *  "Local Port" Portmonitor (localspl.dll / localmon.dll)
+ */
+BOOL WINAPI localmon_AddPortExW(LPWSTR pName, DWORD level, LPBYTE pBuffer, LPWSTR pMonitorName)
+{
+    PORT_INFO_1W * pi;
+    HKEY  hroot;
+    DWORD res;
+
+    pi = (PORT_INFO_1W *) pBuffer;
+    TRACE("(%s, %d, %p, %s) => %s\n", debugstr_w(pName), level, pBuffer, 
+            debugstr_w(pMonitorName), debugstr_w(pi ? pi->pName : NULL));
+
+
+    if ((pMonitorName == NULL) || (lstrcmpiW(pMonitorName, LocalPortW) != 0 ) ||
+        (pi == NULL) || (pi->pName == NULL) || (pi->pName[0] == '\0') ) {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    if (level != 1) {
+        SetLastError(ERROR_INVALID_LEVEL);
+        return FALSE;
+    }
+
+    res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot);
+    if (res == ERROR_SUCCESS) {
+        if (does_port_exist(pi->pName)) {
+            RegCloseKey(hroot);
+            TRACE("=> FALSE with %u\n", ERROR_INVALID_PARAMETER);
+            SetLastError(ERROR_INVALID_PARAMETER);
+            return FALSE;
+        }
+        res = RegSetValueExW(hroot, pi->pName, 0, REG_SZ, (const BYTE *) emptyW, sizeof(emptyW));
+        RegCloseKey(hroot);
+    }
+    if (res != ERROR_SUCCESS) SetLastError(ERROR_INVALID_PARAMETER);
+    TRACE("=> %u with %u\n", (res == ERROR_SUCCESS), GetLastError());
+    return (res == ERROR_SUCCESS);
+}
+
 /*****************************************************
  *   localmon_EnumPortsW [exported through MONITOREX]
  *
@@ -607,8 +665,8 @@ LPMONITOREX WINAPI InitializePrintMonito
             NULL,       /* localmon_ReadPortW */
             NULL,       /* localmon_EndDocPortW */
             NULL,       /* localmon_ClosePortW */
-            NULL,       /* localmon_AddPortW */
-            NULL,       /* localmon_AddPortExW */
+            NULL,       /* Use AddPortUI in localui.dll */
+            localmon_AddPortExW,
             NULL,       /* Use ConfigurePortUI in localui.dll */
             NULL,       /* Use DeletePortUI in localui.dll */
             NULL,       /* localmon_GetPrinterDataFromPort */
-- 
1.4.1



More information about the wine-patches mailing list