Quote:
If a function fails (the return is zero in most cases) then call GetLastError().
Look up the number in help to get an idea of why ie 87 = incorrect param
I agree, I have now added some error checking into my code. Infact I decided to use Formatmessage(); as a separate header file so that I get a clear message of what is wrong(or right)
Quote:
pinfo4 = malloc (dwNeeded) ;
(always check memory allocations)
(How much are you allocating, more than one pinfo in size?)
I am not sure...I just followed the instructions given in MSDN and set the parameters pPrinterEnum = NULL, and cbBuf = 0. As a result the required buffer size is automatically reflected in pcbNeeded.
(SDK doc of Enumprinters())
Quote:
what is the return value from
OpenPrinter(pinfo4->pPrinterName,&hHandle,NULL);
(Is there a valid name in pinfo4->pPrinterName and does hHandle get a value?)
Yes...
pPrinterName does hold a valid name and i crosschecked it with the name of the printer installed.
The hHandle also gets a value.
and The the error checking returned "Operation completed succesfully"
Quote:
did you write any thing to the printer?
WritePrinter(hHandle,buff,sizeof(buff),&dwBytes);
(did dwBytes get a value)
(what is sizeof(buff)?)
sizeof(buff) shows the same value i allocated to buff[] i.e. 1030656 (close to 1mb)
dwBytes also shows the same value as sizeof(buff).
I am sure there is some value in buff[], b'coz i even tried simply writing this data to another .doc file and it works
After the WritePrinter command I get this error message:
"The specified resource type cannot be found in the image file"
can't figure out what that means.
Quote:
I also use PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL
I have two printers installed on my PC and the "post script" printer has been set as default. When I use the above combination, the code tries to select the other (network printer) which in my case is not desirable. So i guess i won't work for me:)
Quote:
I use print info 2 rather than print info 4
I will try that out also and let you know the results...