从打印机驱动程序库调用 GetJob() 的 DllImport 语法出现问题
我正在尝试调用记录的 GetJob() 方法 这里。我认为我现在在例程的语法方面遇到了问题,无论是调用还是定义。我终于得到了一些要编译的东西,如下所示。
[DllImport(
"winspool.drv",
EntryPoint = "GetJob",
SetLastError = true,
CharSet = CharSet.Ansi,
ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern bool GetJob
([InAttribute()] IntPtr hPrinter,
[InAttribute()] Int32 JobId,
[InAttribute()] Int32 Level,
[OutAttribute()] out byte[] pJob,
[InAttribute()] Int32 cbBuf,
[OutAttribute()] out Int32 pcbNeeded);
...
...
...
...
const int BUFFER_SIZE = 250;
int pcbNeeed = 0;
unsafe
{
byte[] byteBuffer = new byte[BUFFER_SIZE];
bResult = GetJob(m_PrinterHandle, jobID, 1, out byteBuffer, BUFFER_SIZE, out pcbNeeed);
}
根据文档此处,看来我应该能够使用byte[] 没有任何特殊的封送代码,因为它是“blittable”。无论如何,我得到一个运行时异常:
无法在 DLL“winspool.drv”中找到名为“GetJob”的入口点。 在 NQBB.Printer.PrintQueueMonitor.PrinterWatcher.GetJob(IntPtr hPrinter, Int32 JobId, Int32 Level, Byte[]& pJob, Int32 cbBuf, Int32& pcbNeeded)
我想我这里只是有一些语法错误。任何人都可以看到问题吗?
I'm trying to call the GetJob() method documented here. I think I'm having problems with the syntax of the routine right now, both calling and defining. I've finally got something to compile which is the following.
[DllImport(
"winspool.drv",
EntryPoint = "GetJob",
SetLastError = true,
CharSet = CharSet.Ansi,
ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern bool GetJob
([InAttribute()] IntPtr hPrinter,
[InAttribute()] Int32 JobId,
[InAttribute()] Int32 Level,
[OutAttribute()] out byte[] pJob,
[InAttribute()] Int32 cbBuf,
[OutAttribute()] out Int32 pcbNeeded);
...
...
...
...
const int BUFFER_SIZE = 250;
int pcbNeeed = 0;
unsafe
{
byte[] byteBuffer = new byte[BUFFER_SIZE];
bResult = GetJob(m_PrinterHandle, jobID, 1, out byteBuffer, BUFFER_SIZE, out pcbNeeed);
}
According to the documentation here, it seems I should be able to use a byte[] without any special marshaling code because it is "blittable". In anycase, I get a runtime exception that says:
Unable to find an entry point named 'GetJob' in DLL 'winspool.drv'.
at NQBB.Printer.PrintQueueMonitor.PrinterWatcher.GetJob(IntPtr hPrinter, Int32 JobId, Int32 Level, Byte[]& pJob, Int32 cbBuf, Int32& pcbNeeded)
I think I just have some syntax wrong here. Can anyone see the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
停止使用 ExactSpelling,然后您将根据需要链接到 GetJobA 或 GetJobW。
Stop using ExactSpelling and then you will link to GetJobA or GetJobW as appropriate.
尝试将 EntryPoint 设置为“GetJobA”。 GetJob实际上并不在winspool导出列表中......
Try setting EntryPoint to "GetJobA". GetJob is not actually in the winspool export list...