Visual c++ 根据打印机状态获取打印机详细信息

Visual c++ 根据打印机状态获取打印机详细信息,visual-c++,Visual C++,在VC++中使用Windows Management Instrumentation(WMI),我们可以找到系统名称和其他属性等系统信息 GetComputerName示例: BOOL WINAPI GetComputerName( _Out_ LPTSTR lpBuffer, _Inout_ LPDWORD lpnSize ); 我的系统中连接了3台打印机1台热敏打印机和2台共享打印机 如何获取脱机打印机的相关信息? 如何根据打印机的状态对其进行分类/列出 谢谢另请参见 DWO

VC++
中使用Windows Management Instrumentation(WMI),我们可以找到系统名称和其他属性等系统信息

GetComputerName示例:

BOOL WINAPI GetComputerName(
  _Out_   LPTSTR  lpBuffer,
  _Inout_ LPDWORD lpnSize
);
我的系统中连接了3台打印机1台热敏打印机和2台共享打印机

如何获取脱机打印机的相关信息?
如何根据打印机的状态对其进行分类/列出

谢谢

另请参见

DWORD flags=PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS;
DWORD bufsize,printerCount;
DWORD级别=2//2代表打印机信息2
::枚举打印机(标志、NULL、级别、NULL、0、&bufsize、&printerCount);
if(bufsize)
{
字节*buffer=新字节[bufsize];
::枚举打印机(标志、NULL、级别、缓冲区、bufsize、&bufsize、&printerCount);
if(bufsize和printerCount)
{
常量打印机信息2*信息=(打印机信息2*)缓冲区;
对于(DWORD i=0;i服务器名称)不能
DWORD flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS;
DWORD bufsize, printerCount;
DWORD level = 2; //2 is for PRINTER_INFO_2

::EnumPrinters(flags, NULL, level, NULL, 0, &bufsize, &printerCount);
if (bufsize)
{
    BYTE* buffer = new BYTE[bufsize];
    ::EnumPrinters(flags, NULL, level, buffer, bufsize, &bufsize, &printerCount);

    if (bufsize && printerCount)
    {
        const PRINTER_INFO_2* info = (PRINTER_INFO_2*)buffer;
        for (DWORD i = 0; i < printerCount; i++)
        {
            if (info->pServerName)  cout << "pServerName: " << info->pServerName << endl;
            if (info->pPrinterName) cout << "pPrinterName: " << info->pPrinterName << endl;
            if (info->pShareName) cout << "pShareName: " << info->pShareName << endl;
            if (info->pPortName) cout << "pPortName: " << info->pPortName << endl;
            if (info->Attributes & PRINTER_ATTRIBUTE_LOCAL) cout << "[local]\n";
            if (info->Attributes & PRINTER_ATTRIBUTE_NETWORK) cout << "[network]\n";

            wcout << "status: " << info->Status << endl;
            if (info->Status & PRINTER_STATUS_ERROR) cout << "status: error\n";

            wcout << endl;
            info++;
        }
    }
    delete[] buffer;
}