我写一个Visual C++程序获取打印作业的详细信息。 代码如下所示:调用API WINSPOOL问题GetJOB
HANDLE hPrinter;
DWORD needed, returned, byteUsed,level;
JOB_INFO_2 *pJobStorage1=NULL;
level = 2;
GetJob(hPrinter, jobId, level, NULL, 0, &needed);
if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER)
cout << "GetJobs failed with error code"
<< GetLastError() << endl;
pJobStorage1 = (JOB_INFO_2 *)malloc(needed);
ZeroMemory(pJobStorage1, needed);
cout << GetJob(hPrinter, jobId, level, (LPBYTE)pJobStorage1, needed, (LPDWORD)&byteUsed) << endl;
cout << pJobStorage1[0].pPrinterName<<endl;
按照documentation,pJobStorage1的输出不是数组,但是,当我更改IDE报错
pJobStorage1[0].pPrinterName
到
pJobStorage1.pPrinterName
所以,我想知道发生了什么。
它不是一个数组。你将它正确地声明为一个指针,并且做了内存管理权(不要忘记free(),让我们不要对新的vs malloc进行挑剔),你只需要' - >'来解引用它。荷兰荷兰。 –