Print this
window
DWORD dwNeeded = 0;
DWORD dwReturned = 0;
PRINTER_INFO_2 *pInfo2; // This one is needed so I can get accross to Win 95/98/NT
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwNeeded, &dwReturned); // Call EnumPrinters the first time to find out the sizes that we need
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) // First call should fail, but it should only fail with the memory error
{
pInfo2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded); // Declare some memory for the printers
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pInfo2, // Make the second call to fill out the elements of the structure
dwNeeded, &dwNeeded, &dwReturned);
UINT printCount;
for (printCount=0;printCount cbPrinterList->Items->Add(pInfo2[printCount].pPrinterName);
if (pInfo2) // Free up the memory that you took for the list
GlobalFree(pInfo2);
} // End the if
else // Something is wrong, notify user
{
cbPrinterList->Enabled = false;
Application->MessageBox("No printers are loaded on this PC\nor not enough memory to list available printers",
"Printer error", MB_OK);
} // End the else