[PATCH] winspool: Forward EnumPrintersA to EnumPrintersW

Detlef Riekenberg wine.dev at web.de
Sun Mar 9 16:50:31 CDT 2008


---
 dlls/winspool.drv/info.c |  197 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 184 insertions(+), 13 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index 7d49d2c..a788ff4 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -251,6 +251,12 @@ static const DWORD di_sizeof[] = {0, sizeof(DRIVER_INFO_1W), sizeof(DRIVER_INFO_
                                      sizeof(DRIVER_INFO_5W), sizeof(DRIVER_INFO_6W),
                                   0, sizeof(DRIVER_INFO_8W)};
 
+static const DWORD pi_sizeof[] = {0, sizeof(PRINTER_INFO_1W), sizeof(PRINTER_INFO_2W),
+                                     sizeof(PRINTER_INFO_3),  sizeof(PRINTER_INFO_4W),
+                                     sizeof(PRINTER_INFO_5W), sizeof(PRINTER_INFO_6),
+                                     sizeof(PRINTER_INFO_7W), sizeof(PRINTER_INFO_8W),
+                                     sizeof(PRINTER_INFO_9W)};
+
 /******************************************************************
  *  validate the user-supplied printing-environment [internal]
  *
@@ -1730,6 +1736,162 @@ static LPDEVMODEA DEVMODEdupWtoA(const DEVMODEW *dmW)
     return dmA;
 }
 
+/******************************************************************
+ * convert_printerinfo_W_to_A [internal]
+ *
+ * strings / structs are converted "inplace"
+ *
+ */
+static void convert_printerinfo_W_to_A(DWORD level, LPBYTE pPrinters, DWORD numentries)
+{
+    CHAR buffer[MAX_PATH];
+    DWORD id = 0;
+    INT len;
+
+    TRACE("(%d, %p, %u)\n", level, pPrinters, numentries);
+    while (id < numentries) {
+        switch (level) {
+            case 1:
+                {
+                    PRINTER_INFO_1W * piW = (PRINTER_INFO_1W *) pPrinters;
+
+                    TRACE("(%u) #%u: %s\n", level, id, debugstr_w(piW->pName));
+
+                    if (piW->pDescription) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pDescription, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pDescription, buffer, len);
+                    }
+                    if (piW->pName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pName, buffer, len);
+                    }
+                    if (piW->pComment) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pComment, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pComment, buffer, len);
+                    }
+                    break;
+                }
+
+            case 2:
+                {
+                    PRINTER_INFO_2W * piW = (PRINTER_INFO_2W *) pPrinters;
+                    LPDEVMODEA dmA;
+
+                    TRACE("(%u) #%u: %s\n", level, id, debugstr_w(piW->pPrinterName));
+                    if (piW->pServerName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pServerName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pServerName, buffer, len);
+                    }
+                    if (piW->pPrinterName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pPrinterName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pPrinterName, buffer, len);
+                    }
+                    if (piW->pShareName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pShareName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pShareName, buffer, len);
+                    }
+                    if (piW->pPortName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pPortName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pPortName, buffer, len);
+                    }
+                    if (piW->pDriverName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pDriverName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pDriverName, buffer, len);
+                    }
+                    if (piW->pComment) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pComment, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pComment, buffer, len);
+                    }
+                    if (piW->pLocation) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pLocation, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pLocation, buffer, len);
+                    }
+
+                    dmA = DEVMODEdupWtoA(piW->pDevMode);
+                    if (dmA) {
+                        memcpy(piW->pDevMode, dmA, dmA->dmSize + dmA->dmDriverExtra);
+                        HeapFree(GetProcessHeap(), 0, dmA);
+                    }
+
+                    if (piW->pSepFile) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pSepFile, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pSepFile, buffer, len);
+                    }
+                    if (piW->pPrintProcessor) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pPrintProcessor, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pPrintProcessor, buffer, len);
+                    }
+                    if (piW->pDatatype) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pDatatype, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pDatatype, buffer, len);
+                    }
+                    if (piW->pParameters) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pParameters, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pParameters, buffer, len);
+                    }
+                    break;
+                }
+
+            case 4:
+                {
+                    PRINTER_INFO_4W * piW = (PRINTER_INFO_4W *) pPrinters;
+
+                    TRACE("(%u) #%u: %s\n", level, id, debugstr_w(piW->pPrinterName));
+
+                    if (piW->pPrinterName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pPrinterName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pPrinterName, buffer, len);
+                    }
+                    if (piW->pServerName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pServerName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pServerName, buffer, len);
+                    }
+                    break;
+                }
+
+            case 5:
+                {
+                    PRINTER_INFO_5W * piW = (PRINTER_INFO_5W *) pPrinters;
+
+                    TRACE("(%u) #%u: %s\n", level, id, debugstr_w(piW->pPrinterName));
+
+                    if (piW->pPrinterName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pPrinterName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pPrinterName, buffer, len);
+                    }
+                    if (piW->pPortName) {
+                        len = WideCharToMultiByte(CP_ACP, 0, piW->pPortName, -1,
+                                                  buffer, sizeof(buffer), NULL, NULL);
+                        memcpy(piW->pPortName, buffer, len);
+                    }
+                    break;
+                }
+
+            default:
+                FIXME("for level %u\n", level);
+        }
+        pPrinters += pi_sizeof[level];
+        id++;
+    }
+}
+
 /***********************************************************
  *             PRINTER_INFO_2AtoW
  * Creates a unicode copy of PRINTER_INFO_2A on heap
@@ -4485,23 +4647,32 @@ BOOL  WINAPI EnumPrintersW(
 }
 
 /******************************************************************
- *              EnumPrintersA        [WINSPOOL.@]
+ * EnumPrintersA    [WINSPOOL.@]
+ *
+ * See EnumPrintersW
  *
  */
-BOOL WINAPI EnumPrintersA(DWORD dwType, LPSTR lpszName,
-			  DWORD dwLevel, LPBYTE lpbPrinters,
-			  DWORD cbBuf, LPDWORD lpdwNeeded,
-			  LPDWORD lpdwReturned)
+BOOL WINAPI EnumPrintersA(DWORD flags, LPSTR pName, DWORD level, LPBYTE pPrinters,
+                          DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
 {
-    BOOL ret, unicode = FALSE;
-    UNICODE_STRING lpszNameW;
-    PWSTR pwstrNameW;
+    BOOL ret;
+    UNICODE_STRING pNameU;
+    LPWSTR pNameW;
+
+    TRACE("(0x%x, %s, %u, %p, %d, %p, %p)\n", flags, debugstr_a(pName), level,
+                                              pPrinters, cbBuf, pcbNeeded, pcReturned);
+
+    pNameW = asciitounicode(&pNameU,pName);
+
+    /* Request a buffer with a size, that is big enough for EnumPrintersW.
+       MS Office need this */
+    ret = EnumPrintersW(flags, pNameW, level, pPrinters, cbBuf, pcbNeeded, pcReturned);
+
+    RtlFreeUnicodeString(&pNameU);
+    if (ret) {
+        convert_printerinfo_W_to_A(level, pPrinters, *pcReturned);
+    }
 
-    pwstrNameW = asciitounicode(&lpszNameW,lpszName);
-    if(!cbBuf) unicode = TRUE; /* return a buffer that's big enough for the unicode version */
-    ret = WINSPOOL_EnumPrinters(dwType, pwstrNameW, dwLevel, lpbPrinters, cbBuf,
-				lpdwNeeded, lpdwReturned, unicode);
-    RtlFreeUnicodeString(&lpszNameW);
     return ret;
 }
 
-- 
1.5.3.6


--=-bsmWZtkAy91kBoHIss2C--




More information about the wine-patches mailing list