这个让我难过。我有一个非常简单的小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机器上,我已经定义了许多打印机,如下面的屏幕截图所示:
列表中的两台物理打印机都已联网但在线且可用。
将驱动程序参数更改为对“WINSPOOL”的CreateDC调用没有帮助。
有什么建议吗?
答案 0 :(得分:0)
解决。原来是一个网络打印机端口,它引用了一个已更改的工作站IP地址,因此ip地址现在无效。虽然没有为默认打印机选择此端口,但似乎仍然以某种方式查询。无论如何,删除端口解决了问题。