I am trying the code below to set the printer settings so that the page setup is Landscape but its not working.

I have been stuck on it for some time now any help is very much appreciated.


HANDLE m_hDevNames=NULL,m_hDevMode=NULL;
PRINTDLG pd2;
// Retrieve MFC's default printer.
AfxGetApp()->GetPrinterDeviceDefaults(&pd2);

// Make our own private copy of MFC's DEVMODE and DEVNAMES data.

// Note: we should NOT GlobalFree the handles returned
// to us in the PRINTDLG structure, because those are the
// actual handles that MFC uses!
m_hDevMode = CopyHandle(pd2.hDevMode);
m_hDevNames = CopyHandle(pd2.hDevNames);


{
// Get default printer settings.
PRINTDLG pd;

pd.lStructSize = (DWORD) sizeof(PRINTDLG);
if (AfxGetApp()->GetPrinterDeviceDefaults(&pd))
{
// Lock memory handle.
DEVMODE FAR* pDevMode =
(DEVMODE FAR*)::GlobalLock(m_hDevMode);
LPDEVNAMES lpDevNames;
LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
HANDLE hPrinter;
TCHAR name[256];
DWORD sz=sizeof(name);
::GetDefaultPrinter(name,&sz);
//_tcscpy(lpszDeviceName,name);
if (pDevMode)
{
// Change printer settings in here.
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
// Unlock memory handle.
lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
lpszDriverName = (LPTSTR )lpDevNames + lpDevNames->wDriverOffset;
lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;
lpszPortName = (LPTSTR )lpDevNames + lpDevNames->wOutputOffset;

BOOL hiya3 = ::OpenPrinter(name/*lpszDeviceName*/, &hPrinter, NULL);
:ocumentProperties(NULL,hPrinter,lpszDeviceName,NULL,//pDevMode,
pDevMode, DM_IN_BUFFER);//|DM_OUT_BUFFER);

// Sync the pDevMode.
// See SDK help for DocumentProperties for more info.
::ClosePrinter(hPrinter);
::GlobalUnlock(m_hDevNames);
::GlobalUnlock(m_hDevMode);
}

}

}

/////////Once above is done I am using the msword automation to print the //document


}
VARIANT vName;
vName.vt = VT_BSTR;
vName.bstrVal = SysAllocString(L"WdPrintOutRange.wdPrintFromTo");
VARIANT vName2;
vName2.vt = VT_BSTR;
vName2.bstrVal = SysAllocString(L"1-2");
TRY
{Doc.PrintOut(covFalse, // Background.
covOptional, // Append.
covOptional, // Range.
covOptional, // OutputFileName.
covOptional, // // From.
covOptional, // // To.
covOptional, // Item.
COleVariant((long)1), // Copies.
covOptional, // Pages.
covOptional, // PageType.
covOptional, // PrintToFile.
covOptional, // Collate.
covOptional, // ActivePrinterMacGX.
covOptional, // ManualDuplexPrint.
covOptional, // PrintZoomColumn New with Word 2002
covOptional, // PrintZoomRow ditto
covOptional, // PrintZoomPaperWidth ditto
covOptional);
}
CATCH(CException, e)
{

return FALSE;
}
END_CATCH

Thanks for your time!
Pauli