1

我正在开发一个在信封上打印地址的程序。作为程序的一部分,我需要更改一些默认打印设置,例如纸张尺寸。为此,我使用下面列出的 DocumentProperties 代码。

 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;`

问题是每次我尝试编译代码时都会出现这些错误

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*'`

我已经尝试将 dev.dmCopies 和 dev.dmFields 更改为 dev->dmCopies 和 dev->dmFields,但是程序刚刚进入 3b,然后退出。根据 MSDN,这些字段应该可以工作(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646843(v=vs.85).aspx),所以我不知道我为什么得到这些错误:(

4

0 回答 0