一个打印API函数的问题?

Tcsind 2002-08-29 02:23:00
Public Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, pJob As Byte, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
函数中pJob的数据类型是BYTE,但资料说它是一个指向Job_Info_1 或 Job_Info_2的数据类型.请问在VB中如何得到pJob中的数据(Job_Info_1结构中的数据?)
...全文
50 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dwenj 2002-08-31
  • 打赏
  • 举报
回复
up
Tcsind 2002-08-31
  • 打赏
  • 举报
回复
在WIN2K中写的.有什么不同吗?
gmc007 2002-08-31
  • 打赏
  • 举报
回复
你的打印任务是在WIN98下生成的还是在NT或WIN2K生成的呢 ?
Tcsind 2002-08-31
  • 打赏
  • 举报
回复
谢谢!谢谢!但是我拿到的总页数和正在打印页数不准.(我的打印机有20M内存)有没有什么更好的方法或提示.
daviddivad 2002-08-29
  • 打赏
  • 举报
回复
BOOL ListJobsForPrinter( LPTSTR szPrinterName )
{

HANDLE hPrinter;
DWORD dwNeeded, dwReturned, i;
JOB_INFO_1 *pJobInfo;

// You need a printer handle, open the printer
if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
return FALSE;

// First you call EnumJobs() to find out how much memory you need
if( ! EnumJobs( hPrinter, 0, 0xFFFFFFFF, 1, NULL, 0, &dwNeeded,
&dwReturned ) )
{
// It should have failed, but if it failed for any reason other
// than "not enough memory", you should bail out
if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
{
ClosePrinter( hPrinter );
return FALSE;
}
}
// Allocate enough memory for the JOB_INFO_1 structures plus
// the extra data - dwNeeded from the previous call tells you
// the total size needed
if( (pJobInfo = (JOB_INFO_1 *)malloc( dwNeeded )) == NULL )
{
ClosePrinter( hPrinter );
return FALSE;
}
// Call EnumJobs() again and let it fill out our structures
if( ! EnumJobs( hPrinter, 0, 0xFFFFFFFF, 1, (LPBYTE)pJobInfo,
dwNeeded, &dwNeeded, &dwReturned ) )
{
ClosePrinter( hPrinter );
free( pJobInfo );
return FALSE;
}
// You're done with the printer handle, close it
ClosePrinter( hPrinter );

// dwReturned tells how many jobs there are
// Here, you'll simply display the number of jobs found
printf( "%d jobs\n", dwReturned );
// It's easy to loop through the jobs and access each one
for(i=0;i<dwReturned;i++)
{
// pJobInfo[i] is a JOB_INFO_1 struct for that job
// so here you could do whatever you want for each job
printf( "[%d] [%s]\n", pJobInfo[i].JobId, pJobInfo[i].pDocument );
}

// Clean up
free( pJobInfo );
return TRUE;
}

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧