Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public static JOB_INFO_2[] getJobsAPI(IntPtr _printerHandle)
  2. {
  3.  
  4. //impressora = identificador(handle)
  5. var hPrinter = _printerHandle;
  6.  
  7. /* Configurações de busca do job em EnumJobs */
  8. uint firstJob = 0;
  9. const uint noJobs = 99;
  10. const uint level = 2;
  11.  
  12. // obtem o tamanho em bytes requeridos para a função
  13. uint needed;
  14. uint returned;
  15. bool b1 = EnumJobsW(hPrinter, firstJob, noJobs, level, IntPtr.Zero, 0, out needed, out returned);
  16. uint lastError = GetLastError();
  17.  
  18. //aloca memoria e popula as estruturas
  19. IntPtr pJob = Marshal.AllocHGlobal((int)needed);
  20. uint bytesCopied;
  21. uint structsCopied;
  22. bool b2 = EnumJobsW(hPrinter, firstJob, noJobs, level, pJob, needed, out bytesCopied, out structsCopied);
  23. var jobInfos = new JOB_INFO_2[structsCopied];
  24. int sizeOf = Marshal.SizeOf(typeof(JOB_INFO_2));
  25. IntPtr pStruct = pJob;
  26.  
  27. for (int i = 0; i < structsCopied; i++)
  28. {
  29. var jobInfo = (JOB_INFO_2)Marshal.PtrToStructure(pStruct, typeof(JOB_INFO_2));
  30. jobInfos[i] = jobInfo;
  31.  
  32. //acessa estrutura DEVMODE
  33. IntPtr pDevMode = jobInfos[i].pDevMode;
  34. DEVMODE devMode = (DEVMODE)Marshal.PtrToStructure(pDevMode, typeof(DEVMODE));
  35. pStruct += sizeOf;
  36. }
  37.  
  38.  
  39. Marshal.FreeHGlobal(pJob);
  40. return jobInfos;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement