comdlg32: Use a helper to update the devmode handle.

This commit is contained in:
Detlef Riekenberg 2012-03-18 22:14:22 +01:00 committed by Alexandre Julliard
parent ce9f046388
commit ecd6f40acb
1 changed files with 112 additions and 58 deletions

View File

@ -254,6 +254,68 @@ static PRINTER_INFO_2A * get_printer_infoA(HANDLE hprn)
return NULL;
}
/***********************************************************************
* update_devmode_handle [internal]
*
* update a devmode handle for the given DEVMODE, alloc the buffer, when needed
*/
static HGLOBAL update_devmode_handleW(HGLOBAL hdm, DEVMODEW *dm)
{
SIZE_T size = GlobalSize(hdm);
LPVOID ptr;
/* Increase / alloc the global memory block, when needed */
if ((dm->dmSize + dm->dmDriverExtra) > size) {
if (hdm)
hdm = GlobalReAlloc(hdm, dm->dmSize + dm->dmDriverExtra, 0);
else
hdm = GlobalAlloc(GMEM_MOVEABLE, dm->dmSize + dm->dmDriverExtra);
}
if (hdm) {
ptr = GlobalLock(hdm);
if (ptr) {
memcpy(ptr, dm, dm->dmSize + dm->dmDriverExtra);
GlobalUnlock(hdm);
}
else
{
GlobalFree(hdm);
hdm = NULL;
}
}
return hdm;
}
static HGLOBAL update_devmode_handleA(HGLOBAL hdm, DEVMODEA *dm)
{
SIZE_T size = GlobalSize(hdm);
LPVOID ptr;
/* Increase / alloc the global memory block, when needed */
if ((dm->dmSize + dm->dmDriverExtra) > size) {
if (hdm)
hdm = GlobalReAlloc(hdm, dm->dmSize + dm->dmDriverExtra, 0);
else
hdm = GlobalAlloc(GMEM_MOVEABLE, dm->dmSize + dm->dmDriverExtra);
}
if (hdm) {
ptr = GlobalLock(hdm);
if (ptr) {
memcpy(ptr, dm, dm->dmSize + dm->dmDriverExtra);
GlobalUnlock(hdm);
}
else
{
GlobalFree(hdm);
hdm = NULL;
}
}
return hdm;
}
/***********************************************************
* convert_to_devmodeA
*
@ -3868,10 +3930,12 @@ BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg)
*/
HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
{
DWORD ret = E_FAIL;
LPVOID ptr;
PRINTER_INFO_2A *pbuf;
DRIVER_INFO_3A *dbuf;
DEVMODEA *dm;
HRESULT hr = S_OK;
HANDLE hprn;
FIXME("(%p) not fully implemented\n", lppd);
if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXA)))
return E_INVALIDARG;
@ -3894,10 +3958,6 @@ HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
if (lppd->Flags & PD_RETURNDEFAULT)
{
PRINTER_INFO_2A *pbuf;
DRIVER_INFO_3A *dbuf;
HANDLE hprn;
if (lppd->hDevMode || lppd->hDevNames)
{
WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
@ -3926,32 +3986,29 @@ HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
ClosePrinter(hprn);
return E_FAIL;
}
ClosePrinter(hprn);
dm = pbuf->pDevMode;
}
else
{
FIXME("(%p) dialog not implemented\n", lppd);
return E_NOTIMPL;
PRINTDLG_CreateDevNames(&(lppd->hDevNames),
dbuf->pDriverPath,
pbuf->pPrinterName,
pbuf->pPortName);
lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
pbuf->pDevMode->dmDriverExtra);
if (lppd->hDevMode)
{
ptr = GlobalLock(lppd->hDevMode);
if (ptr)
{
memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
pbuf->pDevMode->dmDriverExtra);
GlobalUnlock(lppd->hDevMode);
ret = S_OK;
}
}
HeapFree(GetProcessHeap(), 0, pbuf);
HeapFree(GetProcessHeap(), 0, dbuf);
return ret;
}
return E_NOTIMPL;
ClosePrinter(hprn);
PRINTDLG_CreateDevNames(&(lppd->hDevNames), dbuf->pDriverPath, pbuf->pPrinterName, pbuf->pPortName);
if (!lppd->hDevNames)
hr = E_FAIL;
lppd->hDevMode = update_devmode_handleA(lppd->hDevMode, dm);
if (!lppd->hDevMode)
hr = E_FAIL;
HeapFree(GetProcessHeap(), 0, pbuf);
HeapFree(GetProcessHeap(), 0, dbuf);
return hr;
}
/***********************************************************************
@ -3982,10 +4039,11 @@ HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
*/
HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
{
DWORD ret = E_FAIL;
LPVOID ptr;
FIXME("(%p) not fully implemented\n", lppd);
PRINTER_INFO_2W *pbuf;
DRIVER_INFO_3W *dbuf;
DEVMODEW *dm;
HRESULT hr = S_OK;
HANDLE hprn;
if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXW))) {
return E_INVALIDARG;
@ -4010,9 +4068,6 @@ HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
}
if (lppd->Flags & PD_RETURNDEFAULT) {
PRINTER_INFO_2W *pbuf;
DRIVER_INFO_3W *dbuf;
HANDLE hprn;
if (lppd->hDevMode || lppd->hDevNames) {
WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
@ -4040,28 +4095,27 @@ HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
ClosePrinter(hprn);
return E_FAIL;
}
ClosePrinter(hprn);
dm = pbuf->pDevMode;
}
else
{
FIXME("(%p) dialog not implemented\n", lppd);
return E_NOTIMPL;
PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
dbuf->pDriverPath,
pbuf->pPrinterName,
pbuf->pPortName);
lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
pbuf->pDevMode->dmDriverExtra);
if (lppd->hDevMode) {
ptr = GlobalLock(lppd->hDevMode);
if (ptr) {
memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
pbuf->pDevMode->dmDriverExtra);
GlobalUnlock(lppd->hDevMode);
ret = S_OK;
}
}
HeapFree(GetProcessHeap(), 0, pbuf);
HeapFree(GetProcessHeap(), 0, dbuf);
return ret;
}
return E_NOTIMPL;
ClosePrinter(hprn);
PRINTDLG_CreateDevNamesW(&(lppd->hDevNames), dbuf->pDriverPath, pbuf->pPrinterName, pbuf->pPortName);
if (!lppd->hDevNames)
hr = E_FAIL;
lppd->hDevMode = update_devmode_handleW(lppd->hDevMode, dm);
if (!lppd->hDevMode)
hr = E_FAIL;
HeapFree(GetProcessHeap(), 0, pbuf);
HeapFree(GetProcessHeap(), 0, dbuf);
return hr;
}