🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: cn.comp.lang.vc
1 messages
1 total messages Started by fd0129002 Tue, 22 Apr 2008 04:37
[请教]关于GetDefaultPrint函数
#1
Author: fd0129002
Date: Tue, 22 Apr 2008 04:37
18 lines
2580 bytes
请教各位朋友一个问题

以下是我调用GetDefaultPrint函数的代码摘要
现象是
1.当默认打印机名字中含有非ASCII字符时,free(pszDefaultPtr );失败。Debug发现,原因是第一次调用
GetDefaultPrint时返回的buffer大小(dwPrinterName)并不足以存放默认打印机名,于是在第二次调用的时候溢出了。我
第一次调用GetDefaultPrint的时候,GetLastError的返回值是ERROR_INSUFFICIENT_BUFFER。按照
MSDN的说法(The pszBuffer buffer is too small. The variable pointed to by
pcchBuffer contains the required buffer size, in characters. ),貌似不应该在第二
次调用的时候溢出的。
2.当默认打印机名字中只含有ASCII字符时,一切正常。

问题:这是不是GetDefaultPrint函数的一个BUG?或者是我调用的代码有问题?

#include <Winspool.h>
#pragma comment(lib, "Winspool.lib")

...
LPTSTR pszDefaultPtr = NULL;
DWORD dwPrinterName = 0;

...
GetDefaultPrinter(pszDefaultPtr, &dwPrinterName);
pszDefaultPtr = (LPTSTR)calloc(dwPrinterName, sizeof(TCHAR));
GetDefaultPrinter(pszDefaultPtr, &dwPrinterName);
...
free(pszDefaultPtr );
pszDefaultPtr  = NULL;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads