localspl: Implement AddPort
Detlef Riekenberg
wine.dev at web.de
Sun Apr 15 17:47:44 CDT 2007
Native localui.dll calls this function
and works fine in wine with this implementation.
Changelog:
localspl: Implement AddPort
--
By by ... Detlef
-------------- next part --------------
>From 735690c6b59c70a420f513b8c20f2f98f930faa9 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Mon, 16 Apr 2007 00:37:14 +0200
Subject: [PATCH] localmon: Implement AddPort
---
dlls/localspl/localmon.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/dlls/localspl/localmon.c b/dlls/localspl/localmon.c
index 7e13ace..60d2e45 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',
@@ -84,7 +85,9 @@ static const WCHAR cmd_SetDefaultCommCon
'D','e','f','a','u','l','t',
'C','o','m','m','C','o','n','f','i','g',0};
+static const WCHAR dllname_splW[] = {'s','p','o','o','l','s','s','.','d','l','l',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 +129,56 @@ static void dlg_nothingtoconfig(HWND hWn
}
/******************************************************************
+ * does_port_exist (internal)
+ *
+ * returns TRUE, when the Port already exists
+ *
+ */
+BOOL does_port_exist(LPCWSTR myname)
+{
+ HINSTANCE hDLL;
+ DWORD (WINAPI * pEnumPortsW)(LPCWSTR, DWORD, PBYTE, DWORD, LPDWORD, LPDWORD);
+ LPPORT_INFO_1W pi;
+ DWORD needed = 0;
+ DWORD returned;
+ DWORD id;
+
+ TRACE("(%s)\n", debugstr_w(myname));
+
+ hDLL = LoadLibraryW(dllname_splW);
+ if (!hDLL) return FALSE;
+
+ pEnumPortsW = (void *) GetProcAddress(hDLL, "EnumPortsW");
+ if (!pEnumPortsW) {
+ FreeLibrary(hDLL);
+ return FALSE;
+ }
+
+ id = pEnumPortsW(NULL, 1, NULL, 0, &needed, &returned);
+ pi = spl_alloc(needed);
+ returned = 0;
+ if (pi)
+ id = pEnumPortsW(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);
+ FreeLibrary(hDLL);
+ return TRUE;
+ }
+ }
+ }
+
+ spl_free(pi);
+ FreeLibrary(hDLL);
+ return FALSE;
+}
+
+/******************************************************************
* enumerate the local Ports from the Registry (internal)
*
* See localmon_EnumPortsW.
@@ -459,8 +512,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