When I am trying to print the reports the GetPrinter function fails to retrieves the printer information.
First I am trying to get the printer handle for the specified printer using OpenPrinter function. .
HANDLE hPrinter = 0;
OpenPrinter ((LPTSTR)(LPCTSTR)strPrinterAddress, &hPrinter, NULL);
This function gets succeed. Using this printer handle I am trying to access the specified printer informations using the GetPrinter function.
GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded);
DWORD dwError = ::GetLastError();
ClosePrinter( hPrinter );
Even using GetLastError() function I am not able retrieve error message. This function is not failing all the times. When I am trying to print out of 10 times, 6 times the printing is succeed. Only 4 times its getting failed. Please help me shoot out this problem.