获取打印机的状态,但是STATUS一直是0

ice9ying 2013-01-30 10:29:52
RT
像是
pPrinterInfo->pServerName;
pPrinterInfo->pPrinterName;
pPrinterInfo->pShareName;
pPrinterInfo->pPortName;
pPrinterInfo->pDriverName;
都是可以获得的

但是pPrinterInfo->dwStatus 一直是0


代码:
HANDLE hPrinter=0;
DWORD dwNeeded=0;
PRINTER_INFO_2* pPrinterInfo= (PRINTER_INFO_2 *)malloc( 0 );

::OpenPrinter("Samsung SCX-4200 Series",&hPrinter,NULL);

if(!::GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,0,&dwNeeded))
{
pPrinterInfo= (PRINTER_INFO_2 *)malloc( dwNeeded );
::GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,dwNeeded,&dwNeeded);
}
::ClosePrinter(hPrinter);

也用过MSDN中的范例代码,但是一样的结果

望各位高手相助,我完全是半路出家,工作上急着要我又是一头雾水,所以来求助
拜托了!!!!!!!!!!!!!
...全文
1230 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qzxb 2014-08-11
  • 打赏
  • 举报
回复
同求这个问题啊!
chenbingliang 2014-07-11
  • 打赏
  • 举报
回复
楼主解决了吗 最近碰到这问题 获取打印机状态一直为0
ice9ying 2013-02-01
  • 打赏
  • 举报
回复
引用 9 楼 zhao4zhong1 的回复:
也许是你这个Samsung SCX-4200 Series打印机驱动太旧,不支持提交其状态到应用层。 试试用“驱动精灵”看能不能升级这个打印机驱动。 或者打印机实际型号不是或不兼容Samsung SCX-4200 Series打印机驱动? 有条件的话,可以换个别的厂商的打印机试试。
谢谢,我试试看
赵4老师 2013-01-31
  • 打赏
  • 举报
回复
检查所有函数的返回值和GetLastError() ?
ice9ying 2013-01-31
  • 打赏
  • 举报
回复
赵4老师 2013-01-31
  • 打赏
  • 举报
回复
提醒: pPrinterInfo->dwStatus 和 pPrinterInfo->Status 不是一回事!
赵4老师 2013-01-31
  • 打赏
  • 举报
回复
也许是你这个Samsung SCX-4200 Series打印机驱动太旧,不支持提交其状态到应用层。 试试用“驱动精灵”看能不能升级这个打印机驱动。 或者打印机实际型号不是或不兼容Samsung SCX-4200 Series打印机驱动? 有条件的话,可以换个别的厂商的打印机试试。
ice9ying 2013-01-31
  • 打赏
  • 举报
回复
ice9ying 2013-01-31
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
C/C++ code ? 123456789101112 HANDLE hPrinter=0; DWORD dwNeeded=0; PRINTER_INFO_2* pPrinterInfo= (PRINTER_INFO_2 *)malloc( 0 ); /*此处应判断返回值*/::OpenPrinter("Samsung SCX-4200 Series",&hPr……
OpenPrinter 返回true pPrinterInfo不是空值 GetPrinter返回true
赵4老师 2013-01-31
  • 打赏
  • 举报
回复
HANDLE hPrinter=0;
DWORD dwNeeded=0;
PRINTER_INFO_2* pPrinterInfo= (PRINTER_INFO_2 *)malloc( 0 );

/*此处应判断返回值*/::OpenPrinter("Samsung SCX-4200 Series",&hPrinter,NULL);

if(!::GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,0,&dwNeeded))
{
/*此处应判断返回值*/pPrinterInfo= (PRINTER_INFO_2 *)malloc( dwNeeded );
/*此处应判断返回值*/::GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,dwNeeded,&dwNeeded);
}
::ClosePrinter(hPrinter);
赵4老师 2013-01-31
  • 打赏
  • 举报
回复
仅供参考: 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 the pPrinter buffer LPDWORD pcbNeeded // pointer to variable with count of bytes // retrieved (or required) ); Parameters hPrinter Handle to the printer for which the function retrieves information. Use the OpenPrinter function to retrieve a printer handle. Level Specifies the version of the 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, 5, or 7. pPrinter Pointer to a buffer that receives a structure containing information about the specified printer. The buffer must be large enough to receive the structure and any strings or other data that the structure members point to. If the buffer is too small, the pcbNeeded parameter returns the required buffer size. The type of structure is determined by the value of Level. Level Structure 1 A PRINTER_INFO_1 structure containing general printer information. 2 A PRINTER_INFO_2 structure containing detailed information about the printer. 3 Windows NT: A PRINTER_INFO_3 structure containing the printer's security information. 4 Windows NT: A PRINTER_INFO_4 structure containing minimal printer information, including the name of the printer, the name of the server, and whether the printer is remote or local. 5 A PRINTER_INFO_5 structure containing printer information such as printer attributes and time-out settings. 7 Windows NT 5.0 and later: A PRINTER_INFO_7 structure that indicates whether the printer is published in the directory service. 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 in 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, callGetLastError. Remarks Windows NT: For the PRINTER_INFO_2 and PRINTER_INFO_3 structures that contain a pointer to a security descriptor, the function retrieves only those components of the security descriptor that the caller has permission to read. To retrieve particular security descriptor components, you must specify the necessary access rights when you call the OpenPrinter function to retrieve a handle to the printer. The following table shows the access rights required to read the various security descriptor components. Access Right Security Descriptor Component READ_CONTROL Owner Primary group Discretionary access-control list (DACL) ACCESS_SYSTEM_SECURITY System access-control list (SACL) Windows NT 5.0 and later: You can use level 7 with the PRINTER_INFO_7 structure to determine whether the printer is published in the directory service. If the printer is published, the dwAction member of PRINTER_INFO_7 is set to DSPRINT_PUBLISH and the pszObjectGUID member contains the GUID of the directory services print queue object associated with the printer. If the printer is not published, dwAction is set to DSPRINT_UNPUBLISH. PRINTER_INFO_2 The PRINTER_INFO_2 structure specifies detailed printer information. 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; Members pServerName Pointer to a null-terminated string identifying the server that controls the printer. If this string is NULL, the printer is controlled locally. pPrinterName Pointer to a null-terminated string that specifies the name of the printer. pShareName Pointer to a null-terminated string that identifies the sharepoint for the printer. (This string is used only if the PRINTER_ATTRIBUTE_SHARED constant was set for the Attributes member.) pPortName Pointer to a null-terminated string that identifies the port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port must be separated by commas (for example, "LPT1:,LPT2:,LPT3:"). pDriverName Pointer to a null-terminated string that specifies the name of the printer driver. pComment Pointer to a null-terminated string that provides a brief description of the printer. pLocation Pointer to a null-terminated string that specifies the physical location of the printer (for example, "Bldg. 38, Room 1164"). pDevMode Pointer to a DEVMODE structure that defines default printer data such as the paper orientation and the resolution. pSepFile Pointer to a null-terminated string that specifies the name of the file used to create the separator page. This page is used to separate print jobs sent to the printer. pPrintProcessor Pointer to a null-terminated string that specifies the name of the print processor used by the printer. pDatatype Pointer to a null-terminated string that specifies the data type used to record the print job. pParameters Pointer to a null-terminated string that specifies the default print-processor parameters. pSecurityDescriptor Pointer to aSECURITY_DESCRIPTOR structure for the printer. This member may be NULL. Attributes Specifies the printer attributes. This member can be one of the following values: Value Meaning PRINTER_ATTRIBUTE_DEFAULT Windows 95: PRINTER_ATTRIBUTE_DIRECT PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST PRINTER_ATTRIBUTE_ENABLE_BIDI Windows 95: PRINTER_ATTRIBUTE_ENABLE_DEVQ PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS PRINTER_ATTRIBUTE_QUEUED PRINTER_ATTRIBUTE_SHARED PRINTER_ATTRIBUTE_WORK_OFFLINE Windows 95: PRINTER_ATTRIBUTE_PUBLISHED Windows NT 5.0 and later: Indicates whether the printer is published in the directory service. Priority Specifies a priority value that the spooler uses to route print jobs. DefaultPriority Specifies the default priority value assigned to each print job. StartTime Specifies the earliest time at which the printer will print a job. This value is expressed as minutes elapsed since 12:00 A.M. GMT (Greenwich Mean Time). UntilTime Specifies the latest time at which the printer will print a job. This value is expressed as minutes elapsed since 12:00 A.M. GMT (Greenwich Mean Time). Status Specifies the printer status. This member can be one of the following values: Windows NT: PRINTER_STATUS_PAUSED PRINTER_STATUS_PENDING_DELETION Windows 95: PRINTER_STATUS_BUSY PRINTER_STATUS_DOOR_OPEN PRINTER_STATUS_ERROR PRINTER_STATUS_INITIALIZING PRINTER_STATUS_IO_ACTIVE PRINTER_STATUS_MANUAL_FEED PRINTER_STATUS_NO_TONER PRINTER_STATUS_NOT_AVAILABLE PRINTER_STATUS_OFFLINE PRINTER_STATUS_OUT_OF_MEMORY PRINTER_STATUS_OUTPUT_BIN_FULL PRINTER_STATUS_PAGE_PUNT PRINTER_STATUS_PAPER_JAM PRINTER_STATUS_PAPER_OUT PRINTER_STATUS_PAPER_PROBLEM PRINTER_STATUS_PAUSED PRINTER_STATUS_PENDING_DELETION PRINTER_STATUS_PRINTING PRINTER_STATUS_PROCESSING PRINTER_STATUS_TONER_LOW PRINTER_STATUS_UNAVAILABLE PRINTER_STATUS_USER_INTERVENTION PRINTER_STATUS_WAITING PRINTER_STATUS_WARMING_UP cJobs Specifies the number of print jobs that have been queued for the printer. AveragePPM Specifies the average number of pages per minute that have been printed on the printer. Remarks Windows 95: The PRINTER_STATUS_PAGE_PUNT value specifies that the page is being "punted" (that is, not printed) because it is too complex for the printer to print.
ice9ying 2013-01-31
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
检查所有函数的返回值和GetLastError() ?
都没有问题的
ice9ying 2013-01-30
  • 打赏
  • 举报
回复
分不够在技术区,但会往上加的!!!

15,447

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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