1

I'm working on a program that prints addresses on envelopes. As part of the program I need to change some of the default print settings such as paper size. To do this I am using the DocumentProperties code listed below.

 HANDLE hPrinter;
 char pDevice[35];
 strcpy(pDevice,"Test");
 PRINTDLG pd;
 string name;
 ofstream print;
 memset( &pd, 0, sizeof( pd ) );
 pd.lStructSize = sizeof( pd );
 pd.Flags = PD_RETURNDC;
 OpenPrinter(pDevice,&hPrinter,NULL);
 DWORD dwNeeded = ::DocumentProperties(NULL, hPrinter, pDevice, NULL, NULL, 0);
 cout << dwNeeded << endl;
 PDEVMODE  dev = (PDEVMODE)::malloc(dwNeeded);
 cout << "2" << endl;
 DocumentProperties(NULL, hPrinter, pDevice, dev, NULL,  DM_OUT_BUFFER);
 cout << "3" << endl;
 cout << "3b" << endl;        
 dev.dmFields |= DM_COPIES;   // define the number of copies as 3
 cout << "4" << endl;
 dev.dmCopies = 3; // define, which field was changed

 cout << "5" << endl;
 DocumentProperties(NULL,  hPrinter, pDevice,  dev, dev, DM_IN_BUFFER  | DM_OUT_BUFFER);   
 cout << "set" << endl;`

The problem is every time I try to compile the code I get these errors

main.cpp:98:10: error: request for member 'dmFields' in 'dev', which is of non-class type 'DEVMODEA*'
main.cpp:100:19: error: request for member 'dmCopies' in 'dev', which is of non-class type 'DEVMODEA*'`

I've tried changing the dev.dmCopies and dev.dmFields to dev->dmCopies and dev->dmFields, however then the program just gets to 3b, and quits. According to MSDN these fields should work (http://msdn.microsoft.com/en-us/library/windows/desktop/ms646843(v=vs.85).aspx), so I'm dont know why I'm getting these errors :(

0 Answers0