locked
pages per sheet RRS feed

  • Question

  • Hello!

    Unidrv printer settings dialog has option "Pages Per Sheet" and I wonder to know, how to get this value. I've tried to load unidrvui.dll, get address of "DrvQueryJobAttributes" and call this method, but it always returns dwJobNumberOfPagesPerSide == 1. By the way, printer settings dialog store this value correctly. Also tried to call PTConvertDevModeToPrintTicket w/o any success - always returns ERROR_INVALID_DATA, source code below:


    vpd::Devmode devmode(PRINTER_NAME); // get DEVMODE via GetPrinter() and PRINTER_INFO_2
      if (!devmode){
        ERROR_LOG("Converter::getNupSettings(): failed to vpd::Devmode().", GetLastError(), __LINE__, __FILE__);
        return false;
      }
    
      HRESULT result = S_OK;
      Provider provider(nullptr); // RAII wrapper for HPTPROVIDER
      result = PTOpenProvider(PRINTER_NAME, 1, &provider);
      if (FAILED(result)){
        ERROR_LOG("Converter::getNupSettings(): failed to PTOpenProvider().", GetLastError(), __LINE__, __FILE__);
        return false;
      }
    
      IStream *stream = nullptr;
      result = CreateStreamOnHGlobal(nullptr, TRUE, &stream);
      if (FAILED(result)){
        ERROR_LOG("Converter::getNupSettings(): failed to CreateStreamOnHGlobal().", GetLastError(), __LINE__, __FILE__);
        return false;
      }
    
      ULONG cbDevmode = sizeof(DEVMODE);
    
      result = PTConvertDevModeToPrintTicket(provider, cbDevmode, devmode, kPTJobScope, stream);
      if (FAILED(result)){ // Always returns ERROR_INVALID_DATA
        ERROR_LOG("Converter::getNupSettings(): failed to PTConverteDevModeToPrintTicket().", GetLastError(), __LINE__, __FILE__);
        return false;
      }

    How obtain this value?

    Monday, October 20, 2014 8:17 AM

All replies