home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 August / VPR9608A.BIN / del20try / install / data.z / TLHELP32.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-08  |  6KB  |  180 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       Tool Help Functions, Types, and Definitions     }
  6. {                                                       }
  7. {       Copyright (c) 1996 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit TLHelp32;
  12.  
  13. interface
  14.  
  15. uses Windows;
  16.  
  17. const
  18.   MAX_MODULE_NAME32 = 255;
  19.  
  20. (****** Shapshot function **********************************************)
  21.  
  22. function CreateToolhelp32Snapshot(dwFlags, th32ProcessID: DWORD): THandle; stdcall;
  23. //
  24. // The th32ProcessID argument is only used if TH32CS_SNAPHEAPLIST or
  25. // TH32CS_SNAPMODULE is specified. th32ProcessID == 0 means the current
  26. // process.
  27. //
  28. // NOTE that all of the snapshots are global except for the heap and module
  29. //    lists which are process specific. To enumerate the heap or module
  30. //    state for all WIN32 processes call with TH32CS_SNAPALL and the
  31. //    current process. Then for each process in the TH32CS_SNAPPROCESS
  32. //    list that isn't the current process, do a call with just
  33. //    TH32CS_SNAPHEAPLIST and/or TH32CS_SNAPMODULE.
  34. //
  35. // dwFlags
  36. //
  37. const
  38.   TH32CS_SNAPHEAPLIST = $00000001;
  39.   TH32CS_SNAPPROCESS  = $00000002;
  40.   TH32CS_SNAPTHREAD   = $00000004;
  41.   TH32CS_SNAPMODULE   = $00000008;
  42.   TH32CS_SNAPALL      = TH32CS_SNAPHEAPLIST or TH32CS_SNAPPROCESS or
  43.     TH32CS_SNAPTHREAD or TH32CS_SNAPMODULE;
  44.   TH32CS_INHERIT      = $80000000;
  45. //
  46. // Use CloseHandle to destroy the snapshot
  47. //
  48.  
  49. (****** heap walking ***************************************************)
  50.  
  51. type
  52.   PHeapList32 = ^THeapList32;
  53.   THeapList32 = record
  54.     dwSize: DWORD;
  55.     th32ProcessID: DWORD;  // owning process
  56.     th32HeapID: DWORD;     // heap (in owning process's context!)
  57.     dwFlags: DWORD;
  58.   end;
  59. //
  60. // dwFlags
  61. //
  62. const
  63.   HF32_DEFAULT = 1;  // process's default heap
  64.   HF32_SHARED  = 2;  // is shared heap
  65.  
  66. function Heap32ListFirst(hSnapshot: THandle; var lphl: THeapList32): BOOL; stdcall;
  67. function Heap32ListNext(hSnapshot: THandle; var lphl: THeapList32): BOOL; stdcall;
  68.  
  69. type
  70.   PHeapEntry32 = ^THeapEntry32;
  71.   THeapEntry32 = record
  72.     dwSize: DWORD;
  73.     hHandle: THandle;     // Handle of this heap block
  74.     dwAddress: DWORD;      // Linear address of start of block
  75.     dwBlockSize: DWORD;   // Size of block in bytes
  76.     dwFlags: DWORD;
  77.     dwLockCount: DWORD;
  78.     dwResvd: DWORD;
  79.     th32ProcessID: DWORD; // owning process
  80.     th32HeapID: DWORD;    // heap block is in
  81.   end;
  82. //
  83. // dwFlags
  84. //
  85. const
  86.   LF32_FIXED    = $00000001;
  87.   LF32_FREE     = $00000002;
  88.   LF32_MOVEABLE = $00000004;
  89.  
  90. function Heap32First(var lphe: THeapEntry32; th32ProcessID,
  91.   th32HeapID: DWORD): BOOL; stdcall;
  92. function Heap32Next(var lphe: THeapEntry32): BOOL; stdcall;
  93. function Toolhelp32ReadProcessMemory(th32ProcessID: DWORD;
  94.   lpBaseAddress: Pointer; var lpBuffer; cbRead: DWORD;
  95.   var lpNumberOfBytesRead: DWORD): BOOL; stdcall;
  96.  
  97. (***** Process walking *************************************************)
  98.  
  99. type
  100.   PProcessEntry32 = ^TProcessEntry32;
  101.   TProcessEntry32 = record
  102.     dwSize: DWORD;
  103.     cntUsage: DWORD;
  104.     th32ProcessID: DWORD;       // this process
  105.     th32DefaultHeapID: DWORD;
  106.     th32ModuleID: DWORD;        // associated exe
  107.     cntThreads: DWORD;
  108.     th32ParentProcessID: DWORD; // this process's parent process
  109.     pcPriClassBase: Longint;    // Base priority of process's threads
  110.     dwFlags: DWORD;
  111.     szExeFile: array[0..MAX_PATH - 1] of Char;// Path
  112.   end;
  113.  
  114. function Process32First(hSnapshot: THandle; var lppe: TProcessEntry32): BOOL; stdcall;
  115. function Process32Next(hSnapshot: THandle; var lppe: TProcessEntry32): BOOL; stdcall;
  116.  
  117. (***** Thread walking **************************************************)
  118.  
  119. type
  120.   PThreadEntry32 = ^TThreadEntry32;
  121.   TThreadEntry32 = record
  122.     dwSize: DWORD;
  123.     cntUsage: DWORD;
  124.     th32ThreadID: DWORD;       // this thread
  125.     th32OwnerProcessID: DWORD; // Process this thread is associated with
  126.     tpBasePri: Longint;
  127.     tpDeltaPri: Longint;
  128.     dwFlags: DWORD;
  129.   end;
  130.  
  131. function Thread32First(hSnapshot: THandle; var lpte: TThreadEntry32): BOOL; stdcall;
  132. function Thread32Next(hSnapshot: THandle; var lpte: TThreadENtry32): BOOL; stdcall;
  133.  
  134. (***** Module walking *************************************************)
  135.  
  136. type
  137.   PModuleEntry32 = ^TProcessEntry32;
  138.   TModuleEntry32 = record
  139.     dwSize: DWORD;
  140.     th32ModuleID: DWORD;  // This module
  141.     th32ProcessID: DWORD; // owning process
  142.     GlblcntUsage: DWORD;  // Global usage count on the module
  143.     ProccntUsage: DWORD;  // Module usage count in th32ProcessID's context
  144.     modBaseAddr: PBYTE;   // Base address of module in th32ProcessID's context
  145.     modBaseSize: DWORD;   // Size in bytes of module starting at modBaseAddr
  146.     hModule: HMODULE;     // The hModule of this module in th32ProcessID's context
  147.     szModule: array[0..MAX_MODULE_NAME32 + 1] of Char;
  148.     szExePath: array[0..MAX_PATH - 1] of Char;
  149.   end;
  150.  
  151. //
  152. // NOTE CAREFULLY that the modBaseAddr and hModule fields are valid ONLY
  153. // in th32ProcessID's process context.
  154. //
  155.  
  156. function Module32First(hSnapshot: THandle; var lpme: TModuleEntry32): BOOL; stdcall;
  157. function Module32Next(hSnapshot: THandle; var lpme: TModuleEntry32): BOOL; stdcall;
  158.  
  159. implementation
  160.  
  161. const
  162.   kernel32 = 'kernel32.dll';
  163.  
  164. function CreateToolhelp32Snapshot; external kernel32 name 'CreateToolhelp32Snapshot';
  165. function Heap32ListFirst; external kernel32 name 'Heap32ListFirst';
  166. function Heap32ListNext; external kernel32 name 'Heap32ListNext';
  167. function Heap32First; external kernel32 name 'Heap32First';
  168. function Heap32Next; external kernel32 name 'Heap32Next';
  169. function Toolhelp32ReadProcessMemory; external kernel32 name 'Toolhelp32ReadProcessMemory';
  170. function Process32First; external kernel32 name 'Process32First';
  171. function Process32Next; external kernel32 name 'Process32Next';
  172. function Thread32First; external kernel32 name 'Thread32First';
  173. function Thread32Next; external kernel32 name 'Thread32Next';
  174. function Module32First; external kernel32 name 'Module32First';
  175. function Module32Next; external kernel32 name 'Module32Next';
  176.  
  177. end.
  178.  
  179.  
  180.