Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement