dmColor and dmDuplex values of the DEVMODE structure always returning 0

1

I'm doing a print monitoring job in C # and using the winspool API. I was able to capture most of the data I need, such as number of pages, printed document, number of pages printed, user who printed, etc. Using the structure JOB_INFO_2 .

Containing a pointer to a structure DEVMODE where I should get information such as number of copies (dmCopies), whether the print is color or P & B (dmColor), and whether it is a Duplex print (dmDuplex).

I was able to access this structure and some information is correct, for example, dmCopies always returns the correct amount of copies sent for printing, but dmColor which should be 1 for COLOR and 2 for MONOCHROME always returns me 0. The same happens with dmDuplex. It should be 1 for SIMPLEX, 2 for HORIZONTAL and 3 for VERTICAL.

Am I doing something wrong while accessing DEVMODE?

public static JOB_INFO_2[] getJobsAPI(IntPtr _printerHandle)
    {

        //impressora = identificador(handle)
        var hPrinter = _printerHandle;

        /* Configurações de busca do job em EnumJobs */
        uint firstJob = 0;
        const uint noJobs = 99;
        const uint level = 2;

        // obtem o tamanho em bytes requeridos para a função 
        uint needed;
        uint returned;
        bool b1 = EnumJobsW(hPrinter, firstJob, noJobs, level, IntPtr.Zero, 0, out needed, out returned);
        uint lastError = GetLastError();

        //aloca memoria e popula as estruturas
        IntPtr pJob = Marshal.AllocHGlobal((int)needed);
        uint bytesCopied;
        uint structsCopied;
        bool b2 = EnumJobsW(hPrinter, firstJob, noJobs, level, pJob, needed, out bytesCopied, out structsCopied);
        var jobInfos = new JOB_INFO_2[structsCopied];
        int sizeOf = Marshal.SizeOf(typeof(JOB_INFO_2));
        IntPtr pStruct = pJob;

        for (int i = 0; i < structsCopied; i++)
        {
            var jobInfo = (JOB_INFO_2)Marshal.PtrToStructure(pStruct, typeof(JOB_INFO_2));
            jobInfos[i] = jobInfo;

            //acessa estrutura DEVMODE
            IntPtr pDevMode = jobInfos[i].pDevMode;
            DEVMODE devMode = (DEVMODE)Marshal.PtrToStructure(pDevMode, typeof(DEVMODE));
            pStruct += sizeOf;
        }


        Marshal.FreeHGlobal(pJob);
        return jobInfos;
    }
    
asked by anonymous 23.08.2017 / 19:37

0 answers