Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.2 KiB

  1. /**************************************************************************
  2. * TOOLHELP.C
  3. *
  4. * Contains the initalization and deinitialization code for the
  5. * TOOLHELP DLL.
  6. *
  7. **************************************************************************/
  8. #include "toolpriv.h"
  9. #undef VERSION
  10. #include <mmsystem.h>
  11. /* ----- Global variables ----- */
  12. WORD segKernel;
  13. WORD wLibInstalled;
  14. WORD wTHFlags;
  15. HANDLE hMaster;
  16. HANDLE hGDIHeap;
  17. HANDLE hUserHeap;
  18. WORD NEAR *npwExeHead;
  19. WORD NEAR *npwTDBHead;
  20. WORD NEAR *npwTDBCur;
  21. DWORD NEAR *npdwSelTableStart;
  22. WORD NEAR *npwSelTableLen;
  23. FARPROC lpfnGetUserLocalObjType;
  24. FARPROC lpfnFatalExitHook;
  25. FARPROC lpfnNotifyHook;
  26. LPFNUSUD lpfnUserSeeUserDo;
  27. FARPROC lpfnGetFreeSystemResources;
  28. FARPROC lpfntimeGetTime;
  29. WORD wSel;
  30. WORD wLRUCount;
  31. char szKernel[] = "KERNEL";
  32. /* ----- Import values ----- */
  33. #define FATALEXITHOOK MAKEINTRESOURCE(318)
  34. #define GETUSERLOCALOBJTYPE MAKEINTRESOURCE(480)
  35. #define USERSEEUSERDO MAKEINTRESOURCE(216)
  36. #define HASGPHANDLER MAKEINTRESOURCE(338)
  37. #define TOOLHELPHOOK MAKEINTRESOURCE(341)
  38. #define GETFREESYSTEMRESOURCES MAKEINTRESOURCE(284)
  39. /* ToolHelpLibMain
  40. * Called by DLL startup code.
  41. * Initializes TOOLHELP.DLL.
  42. */
  43. int PASCAL ToolHelpLibMain(
  44. HANDLE hInstance,
  45. WORD wDataSeg,
  46. WORD wcbHeapSize,
  47. LPSTR lpszCmdLine)
  48. {
  49. HANDLE hKernel;
  50. HANDLE hUser;
  51. HANDLE hMMSys;
  52. /* Unless we say otherwise, the library is installed OK */
  53. wLibInstalled = TRUE;
  54. /* Do the KERNEL type-checking. Puts the results in global variables */
  55. KernelType();
  56. /* If the KERNEL check failed (not in PMODE) return that the library did
  57. * not correctly install but allow the load anyway.
  58. */
  59. if (!wTHFlags)
  60. {
  61. wLibInstalled = FALSE;
  62. /* Return success anyway, just fails all API calls */
  63. return 1;
  64. }
  65. /* Grab a selector. This is only necessary in Win30StdMode */
  66. if (wTHFlags & TH_WIN30STDMODE)
  67. wSel = HelperGrabSelector();
  68. /* Get the User and GDI heap handles if possible */
  69. hKernel = GetModuleHandle((LPSTR)szKernel);
  70. hUser = GetModuleHandle("USER");
  71. hUserHeap = UserGdiDGROUP(hUser);
  72. hGDIHeap = UserGdiDGROUP(GetModuleHandle("GDI"));
  73. /* Get all the functions we may need. These functions only exist in
  74. * the 3.1 USER and KERNEL.
  75. */
  76. if (!(wTHFlags & TH_WIN30))
  77. {
  78. /* FatalExit hook */
  79. lpfnFatalExitHook = GetProcAddress(hKernel, FATALEXITHOOK);
  80. /* Internal USER routine to get head of class list */
  81. lpfnUserSeeUserDo = (LPFNUSUD)(FARPROC)
  82. GetProcAddress(hUser, USERSEEUSERDO);
  83. /* Identifies objects on USER's local heap */
  84. lpfnGetUserLocalObjType = GetProcAddress(hUser, GETUSERLOCALOBJTYPE);
  85. /* Identifies parameter validation GP faults */
  86. lpfnPV = GetProcAddress(hKernel, HASGPHANDLER);
  87. /* See if the new TOOLHELP KERNEL hook is around */
  88. lpfnNotifyHook = (FARPROC) GetProcAddress(hKernel, TOOLHELPHOOK);
  89. if (lpfnNotifyHook)
  90. wTHFlags |= TH_GOODPTRACEHOOK;
  91. /* Get the USER system resources function */
  92. lpfnGetFreeSystemResources = (FARPROC)
  93. GetProcAddress(hUser, GETFREESYSTEMRESOURCES);
  94. }
  95. /* Make sure we don't ever call these in 3.0 */
  96. else
  97. {
  98. lpfnFatalExitHook = NULL;
  99. lpfnUserSeeUserDo = NULL;
  100. lpfnGetUserLocalObjType = NULL;
  101. lpfnPV = NULL;
  102. }
  103. /* Try to get the multimedia system timer function address */
  104. hMMSys = GetModuleHandle("MMSYSTEM");
  105. if (hMMSys)
  106. {
  107. TIMECAPS tc;
  108. UINT (WINAPI* lpfntimeGetDevCaps)(
  109. TIMECAPS FAR* lpTimeCaps,
  110. UINT wSize);
  111. /* Call the timer API to see if the timer's really installed,
  112. * and if it is, get the address of the get time function
  113. */
  114. lpfntimeGetDevCaps = (UINT(WINAPI *)(TIMECAPS FAR *, UINT))
  115. GetProcAddress(hMMSys, MAKEINTRESOURCE(604));
  116. if ((*lpfntimeGetDevCaps)(&tc, sizeof (tc)) == TIMERR_NOERROR)
  117. lpfntimeGetTime =
  118. GetProcAddress(hMMSys, MAKEINTRESOURCE(607));
  119. }
  120. /* Return success */
  121. return 1;
  122. }