insufficient buffer when call DocumentProperties, also, global unlock wouldn't unlock...
Posted
by Quincy
on Stack Overflow
See other posts from Stack Overflow
or by Quincy
Published on 2010-05-10T22:46:21Z
Indexed on
2010/05/10
23:14 UTC
Read the original article
Hit count: 349
please see comments inline
bool res = false;
DWORD dwNeeded = DocumentPropertiesW(NULL, m_currPrinterHandle, (LPWSTR) m_currPrinterName.c_str(), NULL, NULL, 0);
if (m_devmode_buf)
{
GlobalFree(m_devmode_buf);
}
m_devmode_buf = GlobalAlloc(GPTR, dwNeeded);
GetLastError(); // = 0;
if (m_devmode_buf)
{
LPDEVMODEW devmode_buf = (LPDEVMODEW) GlobalLock(m_devmode_buf);
GetLastError(); // = 0
if (devmode_buf)
{
if (devmode_buf)
{
lala = DocumentPropertiesW(NULL, m_currPrinterHandle, (LPWSTR) m_currPrinterName.c_str(), devmode_buf, NULL, DM_OUT_BUFFER);
if (lala == IDOK)
{
res = true;
}
GetLastError(); // = 122. insufficient buffer here. why????
}
UInt32 res1 = GlobalUnlock(m_devmode_buf); // res1 is 1. should be 0
res2 = GetLastError(); // = 0
if (!(res1 == 0 && (res2 == ERROR_NOT_LOCKED || res2 == NO_ERROR)))
{
//res = false;
}
}
}
© Stack Overflow or respective owner