I'm new to API calls & using Visual C++, I have tried using this code (see
below) from the MSDN website, but get compile errors right at the first
line:

: error C2065: 'LPPRINTDLGEX' : undeclared identifier
: error C2146: syntax error : missing ';' before identifier 'pPDX'
: error C2065: 'pPDX' : undeclared identifier

we are using VFP 6.0 and using the older PrintDLG API call but are getting
an intermittent problem (which is happening more & more as more of our users
are using Window XP) where selecting a printer doesn't work. With Win9X we
just used to run in a loop in VFP to get the user to select the printer
again and it would normally be OK. I'm trying to use 'PPRINTDLGEX' instead
to see if this solves the problem. Is this the best group to post this
question even?! Please help!!! Grant.

HRESULT DisplayPrintPropertySheet(
HWND hWnd // Window that owns the property sheet
)
{
HRESULT hResult;
LPPRINTDLGEX pPDX = NULL;
LPPRINTPAGERANGE pPageRanges = NULL;

// Allocate the PRINTDLGEX structure.

pPDX = (LPPRINTDLGEX)GlobalAlloc(GPTR, sizeof(PRINTDLGEX));
if (!pPDX)
return E_OUTOFMEMORY;

// Allocate an array of PRINTPAGERANGE structures.

pPageRanges = (LPPRINTPAGERANGE) GlobalAlloc(GPTR,
10 * sizeof(PRINTPAGERANGE));
if (!pPageRanges)
return E_OUTOFMEMORY;

// Initialize the PRINTDLGEX structure.

pPDX->lStructSize = sizeof(PRINTDLGEX);
pPDX->hwndOwner = hWnd;
pPDX->hDevMode = NULL;
pPDX->hDevNames = NULL;
pPDX->hDC = NULL;
pPDX->Flags = PD_RETURNDC | PD_COLLATE;
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.

hResult = PrintDlgEx(pPDX);

if ( (hResult == S_OK) &&
pPDX->dwResultAction == PD_RESULT_PRINT) {

// User clicked the Print button, so
// use the DC and other information returned in the
// PRINTDLGEX structure to print the document

}

if (pPDX->hDC != NULL)
DeleteDC(pPDX->hDC);
if (pPDX->hDevMode != NULL)
GlobalFree(pPDX->hDevMode);
if (pPDX->hDevNames != NULL)
GlobalFree(pPDX->hDevNames);

return hResult;
}

Re: using PRINTDLGEX API call to select a printer by Igor

Igor
Wed Nov 23 21:00:17 CST 2005

"Grant" <grant_ahead@hotmail.com> wrote in message
news:OVyep3H8FHA.3928@TK2MSFTNGP10.phx.gbl...
> I'm new to API calls & using Visual C++, I have tried using this code
> (see below) from the MSDN website, but get compile errors right at the
> first line:
>
> : error C2065: 'LPPRINTDLGEX' : undeclared identifier
> : error C2146: syntax error : missing ';' before identifier 'pPDX'
> : error C2065: 'pPDX' : undeclared identifier

Make sure WINVER macro is defined to 0x0500 or higher. Since PRINTDLGEX
is available only on Win2K and above, it is surrounded in the headers by

#if (WINVER >= 0x0500)
#endif

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925