//////////////////////////////////////////////////////////////////// // // File: enumprint.cpp // Project: EnumPrinters() Sample // // Desc: Sample app for EnumPrinters() for Local printers // // Revisions: Created 29/11/98 // // Copyright(C) 1998, Tomas Restrepo. All rights reserved // /////////////////////////////////////////////////////////////////// #include #include int main ( int argc, char *argv[] ) { DWORD dwSizeNeeded; DWORD dwNumItems; DWORD dwItem; LPPRINTER_INFO_2 lpInfo = NULL; // Get buffer size EnumPrinters ( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwSizeNeeded, &dwNumItems ); // allocate memory lpInfo = (LPPRINTER_INFO_2)HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY, dwSizeNeeded ); if ( lpInfo == NULL ) { puts ( "Not enough memory\n" ); return 0; } if ( EnumPrinters ( PRINTER_ENUM_LOCAL, // what to enumerate NULL, // printer name (NULL for all) 2, // level (LPBYTE)lpInfo, // buffer dwSizeNeeded, // size of buffer &dwSizeNeeded, // returns size &dwNumItems // return num. items ) == 0 ) { printf ( "EnumPrinters() Failed with error: %d\n", GetLastError () ); return 0; } // display printers for ( dwItem = 0; dwItem < dwNumItems; dwItem++ ) { printf ( "Printer Name: %s\n" , lpInfo[dwItem].pPrinterName ); if ( lpInfo[dwItem].Attributes & PRINTER_ATTRIBUTE_SHARED ) printf ( "Share Name: %s\n" , lpInfo[dwItem].pShareName ); printf ( "Ports: %s\n" , lpInfo[dwItem].pPortName ); printf ( "Driver Name: %s\n" , lpInfo[dwItem].pDriverName ); printf ( "Comment: %s\n" , lpInfo[dwItem].pComment ); printf ( "Location: %s\n" , lpInfo[dwItem].pLocation ); if ( lpInfo[dwItem].Attributes & PRINTER_ATTRIBUTE_DEFAULT ) puts ( "DEFAULT PRINTER\n" ); // only works on Win9x puts ( "\n" ); } // free memory HeapFree ( GetProcessHeap (), 0, lpInfo ); return 1; } // main()