我想获取打印机的状态,于是我就用了如下的代码
openPrinter(...);//成功返回
GetPrinter(hPrinter, 2, pPrinterInfo, dwNeeded, &dwNeeded);
现在的问题是不管打印实际处于什么状态,pPrinterInfo^.status总是为0,这让我十分的郁闷,
打印机型号:三星 ML-2010 端口是USB001。请各位大侠帮帮忙。
openPrinter(...);//成功返回
GetPrinter(hPrinter, 2, pPrinterInfo, dwNeeded, &dwNeeded);
现在的问题是不管打印实际处于什么状态,pPrinterInfo^.status总是为0,这让我十分的郁闷,
打印机型号:三星 ML-2010 端口是USB001。请各位大侠帮帮忙。
解决方案 »
- 无法定位程序输入点GdiGetImageGraphicsContext于动态链接库zlib1.dll上
- vc从控件名获得控件id或则句柄怎么做啊
- 关于dll的问题.
- 如何让窗口在最前方显示?使用ShowWindow()和SetWindowPos,不用DoModal()
- 我要在ListBox的行与行之间都有一条分隔线该怎么办?
- 几个月没使用VC了,今天刚用,发现入门技巧一个,初学者请看!
- Netmeeting在没有服务器的情况下能实现点对点的通讯,它用的是什么协议?
- 一个拦截WINSOCK API的问题!
- 使用API,如何判断窗口风格!!!!!!!!!!!!!!!!!!
- ****如何在VC中执行WORD的宏?最好有个例子,大送100分!
- 提取文本文件中的字符串
- 多线程问题,怎么不行?
if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))
{
DWORD dwErrorCode = ::GetLastError();
} PRINTER_INFO_2 *pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
if (!GetPrinter(hPrinter,
2,
(LPBYTE)pPrinterInfo,
cByteNeeded,
&cByteUsed))
{
DWORD dwErrorCode = ::GetLastError();
}
DWORD dwNeeded = 0;
PRINTER_INFO_2 *pi2 = NULL;
DEVMODE *pDevMode = NULL;
PRINTER_DEFAULTS pd;
BOOL bFlag;
LONG lFlag;
// Open printer handle (on Windows NT, you need full-access because you
// will eventually use SetPrinter)...
ZeroMemory(&pd, sizeof(pd));
pd.DesiredAccess = PRINTER_ALL_ACCESS;
bFlag = OpenPrinter(lpPrinterName, &hPrinter, &pd);
if(!bFlag || (hPrinter == NULL)) {
AfxMessageBox( "无法打开指定的打印机!" ) ;
return FALSE;
}
// The first GetPrinter tells you how big the buffer should be in
// order to hold all of PRINTER_INFO_2. Note that this should fail with
// ERROR_INSUFFICIENT_BUFFER. If GetPrinter fails for any other reason
// or dwNeeded isn't set for some reason, then there is a problem...
SetLastError(0);
bFlag = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded);
if((!bFlag) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER) || (dwNeeded == 0))
{
ClosePrinter(hPrinter);
AfxMessageBox( "Cannot get the size of the DEVMODE structure" ) ;
return FALSE;
}
// Allocate enough space for PRINTER_INFO_2...
pi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded);
if(pi2 == NULL)
{
ClosePrinter(hPrinter);
return FALSE;
}
// The second GetPrinter fills in all the current settings, so all you
// need to do is modify what you're interested in...
bFlag = GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
if (!bFlag)
{
GlobalFree(pi2);
ClosePrinter(hPrinter);
return FALSE;
}
HANDLE hPrinter = NULL;
DWORD dwNeeded = 0;
PRINTER_INFO_2 *pi2 = NULL;
DEVMODE *pDevMode = NULL;
PRINTER_DEFAULTS pd;
BOOL bFlag;
LONG lFlag;
// Open printer handle (on Windows NT, you need full-access because you
// will eventually use SetPrinter)...
ZeroMemory(&pd, sizeof(pd));
pd.DesiredAccess = PRINTER_ALL_ACCESS;
bFlag = OpenPrinter(lpPrinterName, &hPrinter, &pd);
if(!bFlag || (hPrinter == NULL)) {
AfxMessageBox( "无法打开指定的打印机!" ) ;
return FALSE;
}
// The first GetPrinter tells you how big the buffer should be in
// order to hold all of PRINTER_INFO_2. Note that this should fail with
// ERROR_INSUFFICIENT_BUFFER. If GetPrinter fails for any other reason
// or dwNeeded isn't set for some reason, then there is a problem...
SetLastError(0);
bFlag = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded);
if((!bFlag) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER) || (dwNeeded == 0))
{
ClosePrinter(hPrinter);
AfxMessageBox( "Cannot get the size of the DEVMODE structure" ) ;
return FALSE;
}
// Allocate enough space for PRINTER_INFO_2...
pi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded);
if(pi2 == NULL)
{
ClosePrinter(hPrinter);
return FALSE;
}
// The second GetPrinter fills in all the current settings, so all you
// need to do is modify what you're interested in...
bFlag = GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
if (!bFlag)
{
GlobalFree(pi2);
ClosePrinter(hPrinter);
return FALSE;
}
::GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded);
if(0 < dwNeeded) {
if (::GetPrinter(hPrinter, 2, pPrinterInfo, dwNeeded, &dwNeeded)){
// here you will get "pPrinterInfo"
} }
(小妖)
是正确的!!!
现在的情况是运行代码,PRINTER_INFO_2结构的结果如下:
(“\\test”, “\\test\Samsung ML-2010 Series”, “SamsungM”, “USB001”, “Samsung ML-2010 Series”, “”, “”, $B8CE04, “”, “WinPrint”, “RAW”, “”, $B8CD04, 2584, 1, 0, 0, 0, 0, 0, 0). ↓ ↓
内存地址 内存地址各位大侠在给分析分析。是不是哪里出错了