我正在开发一个在信封上打印地址的程序。作为程序的一部分,我需要更改一些默认的打印设置,如纸张大小。为此,我使用下面列出的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-&gt; dmCopies和dev-&gt; dmFields,然后程序只到3b,然后退出。根据MSDN,这些字段应该有效(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646843(v=vs.85).aspx),所以我不知道为什么我会收到这些错误:(