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

Printing 创建打印机设备上下文成功,除非在windbg下运行应用程序,printing,windbg,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 =

这件事把我难住了。我有一个非常简单的小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;
}
当我在Windows7机器上的控制台窗口中运行它时,我得到了与预期一样的设备上下文句柄,但是当我在windbg下调用它时,我得到了一个06ba异常,CreateDC函数返回一个NULL。在Windows 7机器上,我有许多打印机,如下面的屏幕截图所示:

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

将驱动程序参数更改为CreateDC调用为“WINSPOOL”,没有任何帮助


有什么建议吗?

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

0x000006BA:RPC服务器不可用。@ThomasWeller:谢谢。这很有帮助。