Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Windows Api invalid conversion from LPSTR to LPBYTE
Forum Updated to NodeBB v4.3 + New Features

Windows Api invalid conversion from LPSTR to LPBYTE

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Delavega77
    wrote on 11 Sept 2018, 14:09 last edited by
    #1

    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;

    J 1 Reply Last reply 11 Sept 2018, 14:37
    0
    • D Delavega77
      11 Sept 2018, 14:09

      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;

      J Offline
      J Offline
      JonB
      wrote on 11 Sept 2018, 14:37 last edited by
      #2

      @Delavega77
      Why do you think the 5th parameter is at issue? The error message refers to (LPSTR)pPrinterInfo. Why are you casting that to LPSTR? If it needs a cast it should be to (LPBYTE).

      D 1 Reply Last reply 11 Sept 2018, 15:44
      2
      • D Offline
        D Offline
        Delavega77
        wrote on 11 Sept 2018, 15:24 last edited by
        #3

        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

        1 Reply Last reply
        0
        • J JonB
          11 Sept 2018, 14:37

          @Delavega77
          Why do you think the 5th parameter is at issue? The error message refers to (LPSTR)pPrinterInfo. Why are you casting that to LPSTR? If it needs a cast it should be to (LPBYTE).

          D Offline
          D Offline
          Delavega77
          wrote on 11 Sept 2018, 15:44 last edited by
          #4

          @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

          J A 2 Replies Last reply 11 Sept 2018, 16:29
          0
          • D Delavega77
            11 Sept 2018, 15:44

            @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

            J Offline
            J Offline
            JonB
            wrote on 11 Sept 2018, 16:29 last edited by
            #5

            @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...

            1 Reply Last reply
            0
            • D Delavega77
              11 Sept 2018, 15:44

              @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

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 11 Sept 2018, 16:30 last edited by
              #6

              @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

              Qt has to stay free or it will die.

              D 1 Reply Last reply 12 Sept 2018, 06:19
              3
              • A aha_1980
                11 Sept 2018, 16:30

                @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

                D Offline
                D Offline
                Delavega77
                wrote on 12 Sept 2018, 06:19 last edited by
                #7

                @aha_1980
                Thank you it works

                A J 2 Replies Last reply 12 Sept 2018, 06:23
                1
                • D Delavega77
                  12 Sept 2018, 06:19

                  @aha_1980
                  Thank you it works

                  A Offline
                  A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 12 Sept 2018, 06:23 last edited by
                  #8

                  @Delavega77 Glad it worked. So please mark this topic as SOLVED. Thanks!

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  1
                  • D Delavega77
                    12 Sept 2018, 06:19

                    @aha_1980
                    Thank you it works

                    J Offline
                    J Offline
                    JonB
                    wrote on 12 Sept 2018, 07:34 last edited by
                    #9

                    @Delavega77
                    For your future reference. When you look at the MSDN page for a Windows function like GetPrinter or EnumJobs there are two things you need to act on: you already discovered that it tells you what #includes 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 your LIBS line.

                    1 Reply Last reply
                    2

                    1/9

                    11 Sept 2018, 14:09

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved