Unsolved Windows Api invalid conversion from LPSTR to LPBYTE
-
I found this to get jobs on the queue, but when i try to compile i get invalid conversion :
BOOL printer_Status::GetJobs(HANDLE hPrinter, /* Handle to the printer. */
JOB_INFO_2 **ppJobInfo, /* Pointer to be filled. */ int *pcJobs, /* Count of jobs filled. */ DWORD *pStatus) /* Print Queue status. */
{
DWORD cByteNeeded, nReturned, cByteUsed; JOB_INFO_2 *pJobStorage = NULL; PRINTER_INFO_2 *pPrinterInfo = NULL; /* Get the buffer size needed. */ if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE; } pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded); if (!(pPrinterInfo)) /* Failure to allocate memory. */ return FALSE; /* Get the printer information. */ if (!GetPrinter(hPrinter, 2, (LPSTR)pPrinterInfo, cByteNeeded, &cByteUsed)) //error is here
A for MSDN documentation GetPrinter the 5th parameter is a LPDWORD. I tthink that I'm missing something but I don't what.
Help is much appreciated; -
@Delavega77
Why do you think the 5th parameter is at issue? The error message refers to(LPSTR)pPrinterInfo
. Why are you casting that toLPSTR
? If it needs a cast it should be to(LPBYTE)
. -
I got this error:
I get: invalid conversion from 'LPSTR to 'LPBYTE &cByteUsed))
so I was thinking that the problem is on the 5th parameter. Isn't it?
thank you -
@JonB You are right i casted to LPBYTE and that error diseappear , but now I got undiefned reference to GETPrinterW as weel as EnumJobs. Is a library problem? It seems that including "windows.h" is not enough.
Thank you in advance -
@Delavega77
Do you mean "undefined reference" at compile time or "unresolved external" at link time? It's a lot easier if you copy the actual error for us instead of paraphrasing what you think is relevant... -
@Delavega77 said in Windows Api invalid conversion from LPSTR to LPBYTE:
GETPrinterW
You need to link against the correct library, here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd144911(v=vs.85).aspx they write the function is in
Winspool.lib
So add the following to your project
.pro
file:LIBS += -lwinspool
and run qmake.Regards
-
@aha_1980
Thank you it works -
@Delavega77 Glad it worked. So please mark this topic as SOLVED. Thanks!
-
@Delavega77
For your future reference. When you look at the MSDN page for a Windows function likeGetPrinter
orEnumJobs
there are two things you need to act on: you already discovered that it tells you what#include
s you need to add into your source file, in the same place it also tells you which library the function is defined in, and you need to ensure that library is in yourLIBS
line.