#include "stdafx.h"
#include "conio.h"
#include "windows.h"
int _tmain()
{
char szBuffer[100], szPrinterName[100];
GetProfileStringA("Windows", "Device", ",,,",
szBuffer, sizeof(szBuffer));
char *position = strstr(szBuffer, ",");
RtlZeroMemory(szPrinterName, sizeof(szPrinterName));
strncpy(szPrinterName, szBuffer, position - &szBuffer[0]);
printf("Default printer: %s\n", szPrinterName);
HANDLE hPrinter;
if (OpenPrinterA(szPrinterName, &hPrinter, 0))
{
DWORD dwBufsize;
GetPrinter(hPrinter, 2, NULL, 0, &dwBufsize);
PRINTER_INFO_2* pinfo = (PRINTER_INFO_2*)
GlobalAlloc(GPTR, dwBufsize);
GetPrinter(hPrinter, 2, (LPBYTE)pinfo, dwBufsize, &dwBufsize);
printf("Server name: %ls\n", pinfo->pServerName);
printf("Printer name: %ls\n", pinfo->pPrinterName);
printf("Port name: %ls\n", pinfo->pPortName);
printf("Driver name: %ls\n", pinfo->pDriverName);
printf("Print Processor: %ls\n", pinfo->pPrintProcessor);
printf("\nAttributes: 0x%x\n", pinfo->Attributes);
printf("Status: 0x%x\n", pinfo->Status);
printf("Print jobs queued: %d\n", pinfo->cJobs);
ClosePrinter(hPrinter);
}
else
{
//1801=ERROR_INVALID_PRINTER_NAME
printf("OpenPrinter call failed: %d\n", GetLastError());
}
printf("\nPress any key to exit...\n");
getch();
return 0;
}
|