帮帮我:调用API Enumjobs()的错误!!!(100分)

  • 主题发起人 主题发起人 wyh888666
  • 开始时间 开始时间
W

wyh888666

Unregistered / Unconfirmed
GUEST, unregistred user!
我在调用API Enumjobs()返回打印机队列中的任务时,这样做:
Enumjobs(cphandle,0,1,2,cpjob_info_2,sizeof(cpjob_info_2),cpn,cpr);
如果打印机队列中没有作业,函数调用成功,cpr返回0。
但是打印机队列中有作业,函数调用失败,用formatmessage(...,getlasterror(),...)
提示“122,调用的数据区太小”,我把sizeof(cpjob_info_2)+256,调用是成功,但返回的
job_info_2不对,程序会出错!它说的“数据区”是指的什么的数据区,要怎样才对!!!
帮帮我!!!!!?????
 
Procedure TForm1.GetJobs(PrinterName: String;
JobList: TStrings);
Const
InfoLevel = 1;
FirstJob = 0;
LastJob = 19;
Var
Jobs: Array[FirstJob..LastJob] Of TJobInfo1;
BytesNeeded, I, NumJobs: Dword;
PrinterHandle : THandle;
begin
If OpenPrinter(PChar(PrinterName), PrinterHandle, Nil) then
begin
If
EnumJobs(PrinterHandle, FirstJob, LastJob, InfoLevel, @Jobs, SizeOf(Jobs), BytesNeeded, NumJobs) then
begin
if Numjobs=0 then
begin
showmessage('当前打印机没有打印任务!');
exit;
end;
JobList.Clear;
For I := 0 To NumJobs - 1do
With Jobsdo
JobList.Add(Format('%s(%s)',[StrPas(pDocument),PrinterStatusText(Status)]));
end;
ClosePrinter(PrinterHandle);
end;
end;

Function TForm1.PrinterStatusText(Status: Integer): String;
begin
Case Status Of
0: Result := 'Waiting';
JOB_STATUS_PAUSED: Result := 'Paused';
JOB_STATUS_ERROR: Result := 'Error';
JOB_STATUS_DELETING: Result := 'Deleting';
JOB_STATUS_SPOOLING: Result := 'Spooling';
JOB_STATUS_PRINTING: Result := 'Printing';
JOB_STATUS_OFFLINE: Result := 'Offline';
JOB_STATUS_PAPEROUT: Result := 'Paper Out';
JOB_STATUS_PRINTED: Result := 'Printed';
JOB_STATUS_DELETED: Result := 'Deleted';
JOB_STATUS_BLOCKED_DEVQ: Result := 'Blocked';
JOB_STATUS_USER_INTERVENTION: Result := 'User Intervention';
JOB_STATUS_RESTART: Result := 'Restart';
else
Result := 'Status ' + IntToStr(Status);
end;
end;

Procedure TForm1.Button2Click(Sender: TObject);
begin
GetJobs('HP Laserjet 6P', Memo1.Lines);
end;
 
大虾们关注一下,好吗?我急用!!!
 
To plane822:
如果打印机队列中有两个任务,同样会出错!好像是任务数x,LastJob应为x*10,就是说
如果会有100个任务,LastJob应为1000。
谢谢 plane822。我的问题解决了!!!!
 
接受答案!!
 
后退
顶部