c# 中调用EnumJobs时出问题,有一个参数值返回不回来,有代码,帮忙看看!
using System;
using System.Data;
using System.Runtime.InteropServices;
namespace EnumPrintjobstest
{
class Class1
{
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
static extern bool OpenPrinter(string name,out IntPtr hPrinter, IntPtr pDefault);
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
static extern bool ClosePrinter(IntPtr hPrinter);
// BOOL EnumJobs(
// HANDLE hPrinter, // handle to printer object
// DWORD FirstJob, // index of first job
// DWORD NoJobs, // number of jobs to enumerate
// DWORD Level, // information level
// LPBYTE pJob, // job information buffer
// DWORD cbBuf, // size of job information buffer
// LPDWORD pcbNeeded, // bytes received or required
// LPDWORD pcReturned // number of jobs received
// );
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
// static extern bool EnumJobs(IntPtr hPrinter,int FirstJob,int NoJobs,int Level,out IntPtr pJob,int cbBuf,out int pcbNeeded,out int pcReturned);
static extern bool EnumJobs(IntPtr hPrinter,int FirstJob,int NoJobs,int Level,out IntPtr pJob,int cbBuf,out IntPtr pcbNeeded,out IntPtr pcReturned);
[STAThread]
static void Main(string[] args)
{
string PrintName="\\"+"\\"+"FRANK"+"\\"+"Epson LQ";
EnumJobs(PrintName);
// Console.Write(PrintName.ToString());
string str=Console.ReadLine();
}
private static void EnumJobs(string StrPrintName)
{
bool bRet;
int cbBuf=0;
IntPtr pPrintHand= IntPtr.Zero;
IntPtr Pdef= IntPtr.Zero;
IntPtr pJob=IntPtr.Zero;
// int dwNeeded,dwReturned;
IntPtr dwNeeded,dwReturned;
bRet = OpenPrinter(StrPrintName, out pPrintHand, Pdef);
Console.Write("PrintName:{0}\n",StrPrintName); //ok
Console.Write("PrintHand:{0}\n",pPrintHand); //ok
if (bRet)
{
if( ! EnumJobs( pPrintHand, 0, 256,1,out pJob , 0, out dwNeeded,out dwReturned ) )
{
Console.Write("dwNeeded {0}",dwNeeded); //ok
Console.Write("dwReturned {0}",dwReturned); //error dwReturned数值返回不了?应该时jobs个数
// ......
}
}
else
{
ClosePrinter(pPrintHand);
Console.Write("PrintName error");
}
ClosePrinter(pPrintHand);
}
}
}