有关参数类型

trainee 2005-11-24 07:04:50
C语言不是很好,以下是调用WIN API中一个函数GETPRINTER
.....
HANDLE hPrinter=0;
unsigned long m_count=0;
PRINTER_INFO_2 P_INFO2;
.....
以下语句出错
GetPrinter(hPrinter,2,(LPBYTE)&P_INFO2,sizeof(P_INFO2),&m_count)
出错信息为:传给系统调用的数据区域太小

不知道是哪个参数有问题.我猜想是第3个,请指教,谢谢!

以下GETPRINTER的帮助

--------------------------------------------------------------------------


The GetPrinter function retrieves information about a specified printer.

BOOL GetPrinter(

HANDLE hPrinter, // handle to printer of interest
DWORD Level, // version of printer info data structure
LPBYTE pPrinter, // pointer to array of bytes that receives printer info. structure
DWORD cbBuf, // size, in bytes, of array of bytes
LPDWORD pcbNeeded // pointer to variable with count of bytes retrieved (or required)
);


Parameters

hPrinter

Handle to the printer of interest.

Level

Specifies the level, or type, of PRINTER_INFO_* structure that the function stores into the buffer pointed to by pPrinter.
Windows 95: This value can be 1, 2, or 5.
Windows NT: This value can be 1, 2, 3, 4, or 5.

pPrinter

Pointer to a buffer that receives a PRINTER_INFO_* structure. This structure contains information about the specified printer. The type of structure is determined by the value of Level.
Windows 95: The buffer can receive a PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_5 structure.
Windows NT: The buffer can receive a PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, or PRINTER_INFO_5 structure.

cbBuf

Specifies the size, in bytes, of the buffer pointed to by pPrinter.

pcbNeeded

Pointer to a variable that the function sets to the size in bytes of the printer information. If cbBuf is smaller than this value, GetPrinter fails, and the value represents the required buffer size. If cbBuf is equal to or greater than this value, GetPrinter succeeds, and the value represents the number of bytes stored into the buffer.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call
GetLastError.
_---------------------------------------------------------------------------------------
...全文
119 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
trainee 2005-11-25
  • 打赏
  • 举报
回复
我把它改为
GetPrinter(hPrinter,2,(LPBYTE)&P_INFO2,sizeof(P_INFO2),(LPDWORD)&m_count)
照旧

PRINTER_INFO_2结构如下:
typedef struct _PRINTER_INFO_2 { // pri2
LPTSTR pServerName;
LPTSTR pPrinterName;
LPTSTR pShareName;
LPTSTR pPortName;
LPTSTR pDriverName;
LPTSTR pComment;
LPTSTR pLocation;
LPDEVMODE pDevMode;
LPTSTR pSepFile;
LPTSTR pPrintProcessor;
LPTSTR pDatatype;
LPTSTR pParameters;
PSECURITY_DESCRIPTOR pSecurityDescriptor;
DWORD Attributes;
DWORD Priority;

DWORD DefaultPriority;
DWORD StartTime;
DWORD UntilTime;
DWORD Status;
DWORD cJobs;
DWORD AveragePPM;
} PRINTER_INFO_2;
chinarendotcom 2005-11-24
  • 打赏
  • 举报
回复
),&m_count)

这个大点

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧