void Cdemo_print_win32_cDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
DWORD Flags = PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL; //local printers
DWORD cbBuf;
DWORD pcReturned ;
CString str;
DWORD Level = 2;
TCHAR Name[500] ;
LPPRINTER_INFO_2 pPrinterEnum = NULL ;
memset(Name, 0, sizeof(TCHAR) * 500) ;
::EnumPrinters(Flags, Name, Level, NULL, 0, &cbBuf, &pcReturned) ;
pPrinterEnum = (LPPRINTER_INFO_2)LocalAlloc(LPTR, cbBuf + 4) ;
if (!pPrinterEnum)
{
str.Format(L"error is %d",GetLastError());
MessageBox(str,0,0);
}
if (!EnumPrinters(
Flags, // DWORD Flags, printer object types
Name, // LPTSTR Name, name of printer object
Level, // DWORD Level, information level
(LPBYTE)pPrinterEnum, // LPBYTE pPrinterEnum, printer information buffer
cbBuf, // DWORD cbBuf, size of printer information buffer
&cbBuf, // LPDWORD pcbNeeded, bytes received or required
&pcReturned) // LPDWORD pcReturned number of printers enumerated
)
{
str.Format(L"error is %d",GetLastError());
MessageBox(str,0,0);
}
//memcpy(Name,str,sizeof(TCHAR)*20);
//str.Format(L"return is %d ",pcReturned);
//str.Format(L"%S",Name);
//pPrinterEnum = pPrinterEnum+1;
MessageBox(pPrinterEnum->pPortName,0,0);
// if(pcReturned > 0)
// return true;
// else
// return false;
}