除了在windbg下运行应用程序外,创建打印机设备上下文成功

时间:2018-05-22 05:06:12

标签: printing windbg

这个让我难过。我有一个非常简单的小c程序,如下:

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "windows.h"

int main()
{
    char cPrinter[200];
    DWORD count = 200;
    HDC hDC = NULL;
    GetDefaultPrinterA((LPSTR) &cPrinter, &count);
    printf("Hello world, my printer is %s\n", cPrinter);
    printf("Now I'm going to create a DC...\n");
    hDC = CreateDCA(NULL, cPrinter, NULL, NULL);
    printf("CreateDC returned the value %08x for my DC\n", hDC);
    return 0;
}

当我在Windows 7机器的控制台窗口中运行它时,我得到设备上下文句柄就像我期望的那样,但是当我在windbg下调用它时,我得到一个06ba异常,并且CreateDC函数返回NULL 。在Windows 7机器上,我已经定义了许多打印机,如下面的屏幕截图所示:

the printers I've got defined

列表中的两台物理打印机都已联网但在线且可用。

将驱动程序参数更改为对“WINSPOOL”的CreateDC调用没有帮助。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

解决。原来是一个网络打印机端口,它引用了一个已更改的工作站IP地址,因此ip地址现在无效。虽然没有为默认打印机选择此端口,但似乎仍然以某种方式查询。无论如何,删除端口解决了问题。