Hi,

If I do below code at the bottom of this message without the global free over and over then more and more memory is used without been free'd.
now, if i try and globalfree like below then the memory stays the same... which is good.

but the 2nd run I call it crashes with access violation. looking at the debug the lpDevNames is null:-
void CWinApp::UpdatePrinterSelection(BOOL bForceDefaults)
{
if (!bForceDefaults && m_hDevNames != NULL)
{
LPDEVNAMES lpDevNames = (LPDEVNAMES)::GlobalLock(m_hDevNames);
ASSERT(lpDevNames != NULL);

does anyone have any ideas how to correct this? I have tried unlocking and creating a new instance e.g. PRINTDLG *pd = new PRINTDLG; to no avail.

----------------

void CTestprintdlg_memoryDlg::OnButton1()
{
PRINTDLG pd;
pd.lStructSize = sizeof( pd );

// Get MFC's printer
if(AfxGetApp()->GetPrinterDeviceDefaults(&pd) )
{


if (pd.hDevMode != NULL) GlobalFree(pd.hDevMode);
if (pd.hDevNames != NULL) GlobalFree(pd.hDevNames);

AfxMessageBox("ok");

}
}