Click to See Complete Forum and Search --> : Saving Printer Info Between Sessions


Gary Kibble
May 21st, 1999, 04:33 PM
When I load values for WinApp::m_hDevNames and m_hDevNode into my application, the Print Setup dialog geneates the message "Printer not found" instead of the dialog box.

I'm saving the contents of these structures, not the pointers but somehow the contents appear to be invalid when the program is restarted.

Following are my routines to read and write the data.

Thanks,
Gary

void CPrinterPreferences::LoadSettings( HGLOBAL hDevNames, HGLOBAL hDevMode )
{
// Lock the handles to the structures to get pointers
LPDEVNAMES pDevNames = (LPDEVNAMES)::GlobalLock( hDevNames );
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock( hDevMode );

// Copy the printer information
memcpy( &m_DevNames, pDevNames, sizeof( m_DevNames ) );
memcpy( &m_DevMode, pDevMode, sizeof( m_DevMode ) );

// unlock handles
::GlobalUnlock(hDevNames);
::GlobalUnlock(hDevMode);
}

void CPrinterPreferences::GetSettings( HGLOBAL *p_hDevNames, HGLOBAL *p_hDevMode )
{
// Free the old printer information if it exists
if ( *p_hDevNames != NULL)
::GlobalFree( *p_hDevNames );
if ( *p_hDevMode != NULL)
::GlobalFree( *p_hDevMode );

// Allocate space for the new printer info structures
*p_hDevNames = ::GlobalAlloc(GPTR, sizeof( m_DevNames ) );
*p_hDevMode = ::GlobalAlloc(GPTR, sizeof( m_DevMode ) );

// Lock the new handles
LPDEVNAMES pDevNames = (LPDEVNAMES)::GlobalLock( *p_hDevNames );
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock( *p_hDevMode );

// Copy the printer information
memcpy( pDevNames, &m_DevNames, sizeof( m_DevNames ) );
memcpy( pDevMode, &m_DevMode, sizeof( m_DevMode ) );

::GlobalUnlock( *p_hDevNames );
::GlobalUnlock( *p_hDevMode );
}