Win32 C++ PRINTER_INFO_2 attributes
Win32 C++ PRINTER_INFO_2 attributes
我试图访问PRINTER_INFO_2结构的友好名称属性。但是我不知道怎么用c++来写。
所以下面的代码以十六进制形式返回名称…
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwNeeded = 0, dwPrintersR = 0, Level = 2;
PRINTER_INFO_2* prninfo=NULL;
int retValue = 0;
//Find required buffer size
EnumPrinters( PRINTER_ENUM_NAME, NULL, Level, NULL, 0, &dwNeeded, &dwPrintersR );
prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,dwNeeded);
EnumPrinters( PRINTER_ENUM_NAME, NULL, Level, (LPBYTE) prninfo, dwNeeded, &dwNeeded, &dwPrintersR );
cout << "# of printers:" << dwPrintersR << "n";
for(int i = 0; i<dwPrintersR; i++){
cout << "Printer Name: " << prninfo[i].pPrinterName << "n";
}
_getch();
return 0;
}
我想使用PRINTER_ATTRIBUTE_FRIENDLY_NAME,但我不知道怎么做。
我是c++和编译语言的新手。非常感谢。
代码正常工作,除了它实际上试图将名称打印到控制台窗口。
看起来你正在编译Unicode,所以打印机名称是一个宽字符串(whcar_t *
)。std::ostream::operator<<(wchar_t*)
没有重载,所以你最终得到的只是指针的值,而不是字符串的值。
您需要将宽字符串转换为"ANSI"字符串,编译器为ANSI而不是Unicode,或者使用处理宽字符串的函数输出名称。例如,可以将cout
行替换为:
MessageBox(NULL, prninfo[i].pPrinterName, TEXT("Printer Name"), MB_OK);
或者直接替换
cout & lt; & lt;# of printers:" <<dwPrintersR & lt; & lt;" n";
与
wcout & lt; & lt;L"打印机名称:"<<prninfo[我]。pPrinterName & lt; & lt;L" n";
测试。它工作。
相关文章:
- Mac os x app bundle 在下载并运行时崩溃,但在终端或更改 Info.plist 时运行良好
- "C4649: attributes are ignored in this context"的含义是什么?
- IS类型INFO自动更新了以前调用Destructor
- 提升信息解析器在读取/写入 INFO 格式文件时删除所有注释
- 我如何允许向量传递到info(),capture(),warn()等,同时避免非法扩展std名称空间
- std :: getline(输入,d.info)不起作用
- 什么是log(info)和日志(错误)进行
- 访问冲突错误在 (而 (info[x] != ))
- Electron-无日志消息由C++文件中的log(INFO)打印
- 如何在 WP 8.1 或 WP 8 中的本机C++中使用命名空间 - Microsoft.Phone.Info
- 使用 #define 和 clang 为 info.plist 创建版本号变体
- 使用 sysctl() 的 OSX 上的 info CPU
- 波特迪奥和阿尔萨:"Cannot obtain info for CTL elem"
- gSOAP C++: nillable attributes
- 为什么 boost::thread 构造函数不接受 boost::thread::attributes 参数?
- Win32 C++ PRINTER_INFO_2 attributes
- 我的输出中的D3D11 INFO行是什么意思
- "类形状"没有名为"info"的成员,但添加一个也不起作用