Re: Printing to a shared printer on a network PC,....has anyone do
Hello once again,
I am still stuck.
I modified my code, so when a User selects the Menu Item for Printer setup,
the following routine is invoked.
/*
Printer Setup Option was selected from the Menu.
Open a Common PRINTDLGEX Dialog to establish the Printer Defaults
*/
int CPrinterControl::OnPrinterOptionsSetupPrinter_2()
{
HRESULT hResult;
LPPRINTDLGEX pPDX = NULL;
LPPRINTPAGERANGE pPageRanges = NULL;
int iReturnCode=PD_RESULT_CANCEL;
// Allocate the PRINTDLGEX structure.
pPDX = (LPPRINTDLGEX)GlobalAlloc(GPTR, sizeof(PRINTDLGEX));
if (!pPDX)
return(iReturnCode);
// Allocate an array of PRINTPAGERANGE structures.
pPageRanges = (LPPRINTPAGERANGE) GlobalAlloc(GPTR, 10 *
sizeof(PRINTPAGERANGE));
if (!pPageRanges)
{
GlobalUnlock(pPDX); // unlock the memory for other functions to use
this
GlobalFree(pPDX); // free the memory for other functions to use this
return(iReturnCode);
}
// Initialize the PRINTDLGEX structure.
pPDX->lStructSize = sizeof(PRINTDLGEX);
pPDX->hwndOwner = m_pWndOwner->m_hWnd;
pPDX->hDevMode = NULL;
pPDX->hDevNames = NULL;
pPDX->hDC = NULL;
pPDX->Flags = PD_RETURNDC | PD_COLLATE | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS
| PD_NOSELECTION | PD_NOCURRENTPAGE;
pPDX->Flags2 = 0;
pPDX->ExclusionFlags = 0;
pPDX->nPageRanges = 0;
pPDX->nMaxPageRanges = 10;
pPDX->lpPageRanges = pPageRanges;
pPDX->nMinPage = 1;
pPDX->nMaxPage = 1000;
pPDX->nCopies = 1;
pPDX->hInstance = 0;
pPDX->lpPrintTemplateName = NULL;
pPDX->lpCallback = NULL;
pPDX->nPropertyPages = 0;
pPDX->lphPropertyPages = NULL;
pPDX->nStartPage = START_PAGE_GENERAL;
pPDX->dwResultAction = 0;
// Invoke the Print property sheet.
/*
If the function succeeds, the return value is S_OK and the dwResultAction
member of
the PRINTDLGEX structure contains one of the following values.
PD_RESULT_APPLY The user clicked the Apply button and later clicked the
Cancel button.
This indicates that the user wants to apply the changes made in the
property
sheet, but does not yet want to print.
The PRINTDLGEX structure contains the information specified by the
user at
the time the Apply button was clicked.
PD_RESULT_CANCEL The user clicked the Cancel button.
The information in the PRINTDLGEX structure is unchanged.
PD_RESULT_PRINT The user clicked the Print button.
The PRINTDLGEX structure contains the information specified by the
user.
*/
hResult = PrintDlgEx(pPDX);
if (hResult == S_OK)
{
m_pDevMode = (DEVMODE *) GlobalLock(pPDX->hDevMode); // Lock the memory
so I can return a pointer to it
m_pDevNames = (DEVNAMES *) GlobalLock(pPDX->hDevNames); // Lock the memory
so I can return a pointer to it
if ( m_pDevMode )
{
/* Write the new Page Orientation, Page Size, and Printer Name to the INI
file */
m_ProcessIni.m_szIniFileName.LoadString(IDS_INIFILENAME);
m_ProcessIni.setINIFileName(m_ProcessIni.m_szIniFileName);
m_ProcessIni.getSectionData(m_ProcessIni.m_szIniSectionName);
m_PageOrientation = m_pDevMode->dmOrientation; // Save the orientation
m_PaperSize = m_pDevMode->dmPaperSize; // Save the paper size
m_ProcessIni.m_szIniKeyName.LoadString(IDS_PAGEORIENTATION);
m_ProcessIni.m_szIniKeyValue.Format("%d", m_PageOrientation);
m_ProcessIni.setKey(m_ProcessIni.m_szIniKeyValue,
m_ProcessIni.m_szIniKeyName, m_ProcessIni.m_szIniSectionName);
m_ProcessIni.m_szIniKeyName.LoadString(IDS_PAPERSIZE);
m_ProcessIni.m_szIniKeyValue.Format("%d", m_PaperSize);
m_ProcessIni.setKey(m_ProcessIni.m_szIniKeyValue,
m_ProcessIni.m_szIniKeyName, m_ProcessIni.m_szIniSectionName);
m_ProcessIni.m_szIniKeyName.LoadString(IDS_PAPERDUPLEX);
m_ProcessIni.m_szIniKeyValue.Format("%d", m_Duplex);
m_ProcessIni.setKey(m_ProcessIni.m_szIniKeyValue,
m_ProcessIni.m_szIniKeyName, m_ProcessIni.m_szIniSectionName);
/*
The printer name stored in this field in the DEVMODE structure is
limited to 32 characters.
Network printers can typically, have much longer names.
So, now we grab it from the DEVNAMEs structure.
It is embedded in the DEVNAMES structure past the four WORD values that
make up
the data as seen in the documentation.
Essentially, the DEVNAMES structure definition is really a header block
in front of a
memory block containing the information about the printer.
In this manner the name of the printer may be any length, unlike the
DEVMODE.dmDeviceName
member which is 32 bytes.
We use the DEVMODE structure to grab the other information (paper
orientation, paper size, etc.).
*/
m_ProcessIni.m_szIniKeyName.LoadString(IDS_PRINTERNAME); // Save the
Printer Name
m_ProcessIni.m_szIniKeyValue.Format("%s", m_pDevMode->dmDeviceName);
m_ProcessIni.m_szIniKeyValue.Format("%s", ((LPSTR)m_pDevNames) +
m_pDevNames->wDeviceOffset);
m_ProcessIni.setKey(m_ProcessIni.m_szIniKeyValue,
m_ProcessIni.m_szIniKeyName, m_ProcessIni.m_szIniSectionName);
}
if (pPDX->dwResultAction == PD_RESULT_PRINT || pPDX->dwResultAction ==
PD_RESULT_APPLY)
{
iReturnCode=pPDX->dwResultAction;
CloseThePrinter();
m_dc.DeleteDC();
}
}
if (pPDX->hDC != NULL)
CDC::FromHandle(pPDX->hDC)->DeleteDC();
if (pPDX->hDevMode != NULL)
{
GlobalUnlock(pPDX->hDevMode);
GlobalFree(pPDX->hDevMode);
}
if (pPDX->hDevNames != NULL)
{
GlobalUnlock(pPDX->hDevNames);
GlobalFree(pPDX->hDevNames);
}
if (pPDX->lpPageRanges != NULL)
{
GlobalUnlock(pPDX->lpPageRanges);
GlobalFree(pPDX->lpPageRanges);
}
if (pPDX != NULL)
{
GlobalUnlock(pPDX);
GlobalFree(pPDX);
}
return(iReturnCode);
}
After the routine starts, and the PrintDlgEx is instantiated, I choose the
shared printer from one of my other machines, and I see the following errors
(which suggest obviously, that I simply don't have access to the printer. But
I can print to it using NotePad or Word or Excel or Visio.....
'ChiroPracticeOffice.exe': Loaded
'C:\WINNT\system32\spool\drivers\w32x86\3\hpz2ku10.dll', Binary was not built
with debug information.
Invalid source devmode at startFirst-chance exception at 0x6063db1e in
ChiroPracticeOffice.exe: 0xC0000005: Access violation reading location
0x00000008.
First-chance exception at 0x6063db1e in ChiroPracticeOffice.exe: 0xC0000005:
Access violation reading location 0x00000008.
First-chance exception at 0x6063db1e in ChiroPracticeOffice.exe: 0xC0000005:
Access violation reading location 0x00000008.
First-chance exception at 0x6063db1e in ChiroPracticeOffice.exe: 0xC0000005:
Access violation reading location 0x00000008.
Invalid devmode at end'ChiroPracticeOffice.exe': Unloaded
'C:\WINNT\system32\spool\drivers\w32x86\3\hpzrm310.dll'
'ChiroPracticeOffice.exe': Unloaded 'C:\WINNT\system32\compstui.dll'
'ChiroPracticeOffice.exe': Unloaded 'C:\WINNT\system32\msimg32.dll'
I really don 't mean to take up so much of anyone's time. I am just not sure
where to look.
Thanks,