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)
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 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.
pinfo4 = malloc (dwNeeded) ;
(always check memory allocations)
(How much are you allocating, more than one pinfo in size?)
(SDK doc of Enumprinters())
what is the return value from
(Is there a valid name in pinfo4->pPrinterName and does hHandle get a value?)
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"
sizeof(buff) shows the same value i allocated to buff i.e. 1030656 (close to 1mb)
did you write any thing to the printer?
(did dwBytes get a value)
(what is sizeof(buff)?)
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.
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:)
I also use PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL
I will try that out also and let you know the results...
I use print info 2 rather than print info 4