从打印机驱动程序库调用 GetJob() 的 DllImport 语法出现问题

发布于 2024-12-04 05:42:23 字数 1309 浏览 4 评论 0原文

我正在尝试调用记录的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在风中等你 2024-12-11 05:42:23

停止使用 ExactSpelling,然后您将根据需要链接到 GetJobA 或 GetJobW。

Stop using ExactSpelling and then you will link to GetJobA or GetJobW as appropriate.

洒一地阳光 2024-12-11 05:42:23

尝试将 EntryPoint 设置为“GetJobA”。 GetJob实际上并不在winspool导出列表中......

Try setting EntryPoint to "GetJobA". GetJob is not actually in the winspool export list...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文