localui: [2/2] Implement DeletePortUI

Detlef Riekenberg wine.dev at web.de
Sun Apr 15 17:47:39 CDT 2007


Changelog:
localui: Implement DeletePortUI


-- 
 
By by ... Detlef

-------------- next part --------------
>From ae20150ad47c54eee1a76731ed41d868b89c16e3 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Mon, 16 Apr 2007 00:31:24 +0200
Subject: [PATCH] localui: Implement DeletePortUI
---
 dlls/localui/Makefile.in |    2 +
 dlls/localui/localui.c   |   76 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/dlls/localui/Makefile.in b/dlls/localui/Makefile.in
index f002e23..55c827e 100644
--- a/dlls/localui/Makefile.in
+++ b/dlls/localui/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = localui.dll
-IMPORTS   = kernel32
+IMPORTS   = kernel32 winspool
 
 C_SRCS = \
 	localui.c
diff --git a/dlls/localui/localui.c b/dlls/localui/localui.c
index ae512e0..70ae0fc 100644
--- a/dlls/localui/localui.c
+++ b/dlls/localui/localui.c
@@ -36,6 +36,50 @@ WINE_DEFAULT_DEBUG_CHANNEL(localui);
 
 static HINSTANCE LOCALUI_hInstance;
 
+static const WCHAR cmd_DeletePortW[] = {'D','e','l','e','t','e','P','o','r','t',0};
+static const WCHAR XcvPortW[] = {',','X','c','v','P','o','r','t',' ',0};
+
+/*****************************************************
+ *   strdupWW [internal]
+ */
+
+static LPWSTR strdupWW(LPCWSTR pPrefix, LPCWSTR pSuffix)
+{
+    LPWSTR  ptr;
+    DWORD   len;
+
+    len = lstrlenW(pPrefix) + lstrlenW(pSuffix) + 1;
+    ptr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (ptr) {
+        lstrcpyW(ptr, pPrefix);
+        lstrcatW(ptr, pSuffix);
+    }
+    return ptr;
+}
+
+/*****************************************************
+ *   open_monitor_by_name [internal]
+ *
+ */
+static BOOL open_monitor_by_name(LPCWSTR pPrefix, LPCWSTR pPort, HANDLE * phandle)
+{
+    PRINTER_DEFAULTSW pd;
+    LPWSTR  fullname;
+    BOOL    res;
+
+    * phandle = 0;
+    TRACE("(%s,%s)\n", debugstr_w(pPrefix),debugstr_w(pPort) );
+
+    fullname = strdupWW(pPrefix, pPort);
+    pd.pDatatype = NULL;
+    pd.pDevMode  = NULL;
+    pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
+
+    res = OpenPrinterW(fullname, phandle, &pd);
+    HeapFree(GetProcessHeap(), 0, fullname);
+    return res;    
+}
+
 /*****************************************************
  *   localui_AddPortUI [exported through MONITORUI]
  *
@@ -94,11 +138,39 @@ static BOOL WINAPI localui_ConfigurePort
  *  Success: TRUE
  *  Failure: FALSE
  *
+ * NOTES
+ *  Native localui does not allow to delete a COM / LPT - Port (ERROR_NOT_SUPPORTED)
+ *
  */
 static BOOL WINAPI localui_DeletePortUI(PCWSTR pName, HWND hWnd, PCWSTR pPortName)
 {
-    FIXME("(%s, %p, %s) stub\n", debugstr_w(pName), hWnd, debugstr_w(pPortName));
-    return TRUE;
+    HANDLE  hXcv;
+    DWORD   dummy;
+    DWORD   needed;
+    DWORD   status;
+
+    TRACE("(%s, %p, %s)\n", debugstr_w(pName), hWnd, debugstr_w(pPortName));
+
+    if ((!pPortName) || (!pPortName[0])) {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    if (open_monitor_by_name(XcvPortW, pPortName, &hXcv)) {
+        /* native localui tests here for LPT / COM - Ports and failed with
+           ERROR_NOT_SUPPORTED. */
+        if (XcvDataW(hXcv, cmd_DeletePortW, (LPBYTE) pPortName,
+            (lstrlenW(pPortName)+1) * sizeof(WCHAR), (LPBYTE) &dummy, 0, &needed, &status)) {
+
+            ClosePrinter(hXcv);
+            if (status != ERROR_SUCCESS) SetLastError(status);
+            return (status == ERROR_SUCCESS);            
+        }
+        ClosePrinter(hXcv);
+        return FALSE;
+    }
+    SetLastError(ERROR_UNKNOWN_PORT);
+    return FALSE;
 }
 
 /*****************************************************
-- 
1.4.1



More information about the wine-patches mailing list