From 2a70c594b89bb1f448062bd6c7c8024779fdcf39 Mon Sep 17 00:00:00 2001
From: tatyana <tatyana@etersoft.ru>
Date: Fri, 4 Jan 2013 20:36:56 +0400
Subject: [eter-2.0.0] winspool.drv: Get default DEVMODEW if fMode not equal
 DM_IN_BUFFER(eterbug #8821)

---
 dlls/winspool.drv/info.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index 5597823..b86d2e4 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -1737,7 +1737,7 @@ LONG WINAPI DocumentPropertiesA(HWND hWnd,HANDLE hPrinter,
 	hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
     );
 
-    if(!pDeviceName) {
+    if(!pDeviceName || !strcmp(pDeviceName,"")) {
         LPCWSTR lpNameW = get_opened_printer_name(hPrinter);
         if(!lpNameW) {
 		ERR("no name from hPrinter?\n");
@@ -1777,10 +1777,23 @@ LONG WINAPI DocumentPropertiesW(HWND hWnd, HANDLE hPrinter,
 {
 
     LPSTR pDeviceNameA = strdupWtoA(pDeviceName);
-    LPDEVMODEA pDevModeInputA = DEVMODEdupWtoA(pDevModeInput);
     LPDEVMODEA pDevModeOutputA = NULL;
     LONG ret;
+    LPDEVMODEA pDevModeInputA;
 
+    DWORD size;
+    DWORD buflen = sizeof(DEVMODEW);
+    LPBYTE ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen);
+
+    if(!(fMode&DM_IN_BUFFER))
+    {
+        WINSPOOL_GetDefaultDevMode(ptr, buflen, &size);
+        if(!pDevModeInput)
+            pDevModeInput = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
+        memcpy(pDevModeInput, ptr, size);
+    }
+
+    pDevModeInputA = DEVMODEdupWtoA(pDevModeInput);
     TRACE("(%p,%p,%s,%p,%p,%d)\n",
           hWnd,hPrinter,debugstr_w(pDeviceName),pDevModeOutput,pDevModeInput,
 	  fMode);
@@ -1799,6 +1812,7 @@ LONG WINAPI DocumentPropertiesW(HWND hWnd, HANDLE hPrinter,
         ret += (CCHDEVICENAME + CCHFORMNAME);
     HeapFree(GetProcessHeap(),0,pDevModeInputA);
     HeapFree(GetProcessHeap(),0,pDeviceNameA);
+    HeapFree(GetProcessHeap(),0,ptr);
     return ret;
 }
 
-- 
1.7.12.4
