Leaked source code of windows server 2003
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.

158 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. e.cpp
  5. Abstract:
  6. This DLL Hooks CreateWindow, DialogBox, and CreateDialog routines in order to
  7. ensure that Comctl32 version 5 is loaded.
  8. Notes:
  9. This is a general purpose shim.
  10. History:
  11. 05/25/2000 lamadio Added initial shims to ensure that comctl32 version 6
  12. is loaded.
  13. --*/
  14. #include "precomp.h"
  15. #include <stdio.h>
  16. IMPLEMENT_SHIM_BEGIN(LoadComctl32Version5)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(CreateWindowExA)
  20. APIHOOK_ENUM_ENTRY(CreateWindowExW)
  21. APIHOOK_ENUM_ENTRY(DialogBoxParamA)
  22. APIHOOK_ENUM_ENTRY(DialogBoxParamW)
  23. APIHOOK_ENUM_ENTRY(DialogBoxIndirectParamA)
  24. APIHOOK_ENUM_ENTRY(DialogBoxIndirectParamW)
  25. APIHOOK_ENUM_ENTRY(CreateDialogParamA)
  26. APIHOOK_ENUM_ENTRY(CreateDialogParamW)
  27. APIHOOK_ENUM_ENTRY(CreateDialogIndirectParamA)
  28. APIHOOK_ENUM_ENTRY(CreateDialogIndirectParamW)
  29. APIHOOK_ENUM_END
  30. BOOL g_fComctl32V5Loaded = FALSE;
  31. typedef BOOL (__stdcall *PFNInitCommonControlsEx)(LPINITCOMMONCONTROLSEX);
  32. void EnsureComctl32Version5IsLoaded()
  33. {
  34. if (g_fComctl32V5Loaded == FALSE) {
  35. HMODULE hMod = GetModuleHandle(TEXT("Comctl32.dll"));
  36. if (hMod == NULL) {
  37. hMod = LoadLibrary(TEXT("Comctl32.dll"));
  38. if (hMod) {
  39. PFNInitCommonControlsEx pfn = (PFNInitCommonControlsEx)GetProcAddress(hMod, "InitCommonControlsEx");
  40. if (pfn) {
  41. INITCOMMONCONTROLSEX icc;
  42. icc.dwSize = sizeof(icc);
  43. icc.dwICC = 0x00003FFF; // Initialize all classes.
  44. pfn(&icc);
  45. }
  46. }
  47. }
  48. g_fComctl32V5Loaded = TRUE; // Well, we tried. If we failed, we shouldn't try more than once.
  49. }
  50. }
  51. HWND APIHOOK(CreateWindowExA)(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y,
  52. int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
  53. {
  54. EnsureComctl32Version5IsLoaded();
  55. return ORIGINAL_API(CreateWindowExA)(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
  56. nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
  57. }
  58. HWND APIHOOK(CreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y,
  59. int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
  60. {
  61. EnsureComctl32Version5IsLoaded();
  62. return ORIGINAL_API(CreateWindowExW)(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
  63. nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
  64. }
  65. INT_PTR APIHOOK(DialogBoxParamA)(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  66. {
  67. EnsureComctl32Version5IsLoaded();
  68. return ORIGINAL_API(DialogBoxParamA)(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  69. }
  70. INT_PTR APIHOOK(DialogBoxParamW)(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  71. {
  72. EnsureComctl32Version5IsLoaded();
  73. return ORIGINAL_API(DialogBoxParamW)(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  74. }
  75. INT_PTR APIHOOK(DialogBoxIndirectParamA)(HINSTANCE hInstance, LPCDLGTEMPLATEA hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  76. {
  77. EnsureComctl32Version5IsLoaded();
  78. return ORIGINAL_API(DialogBoxIndirectParamA)(hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam);
  79. }
  80. INT_PTR APIHOOK(DialogBoxIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW hDialogTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  81. {
  82. EnsureComctl32Version5IsLoaded();
  83. return ORIGINAL_API(DialogBoxIndirectParamW)(hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam);
  84. }
  85. HWND APIHOOK(CreateDialogParamA)(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  86. {
  87. EnsureComctl32Version5IsLoaded();
  88. return ORIGINAL_API(CreateDialogParamA)(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  89. }
  90. HWND APIHOOK(CreateDialogParamW)(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  91. {
  92. EnsureComctl32Version5IsLoaded();
  93. return ORIGINAL_API(CreateDialogParamW)(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  94. }
  95. HWND APIHOOK(CreateDialogIndirectParamA)(HINSTANCE hInstance, LPCDLGTEMPLATEA lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  96. {
  97. EnsureComctl32Version5IsLoaded();
  98. return ORIGINAL_API(CreateDialogIndirectParamA)(hInstance, lpTemplate, hWndParent, lpDialogFunc, dwInitParam);
  99. }
  100. HWND APIHOOK(CreateDialogIndirectParamW)(HINSTANCE hInstance, LPCDLGTEMPLATEW lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  101. {
  102. EnsureComctl32Version5IsLoaded();
  103. return ORIGINAL_API(CreateDialogIndirectParamW)(hInstance, lpTemplate, hWndParent, lpDialogFunc, dwInitParam);
  104. }
  105. /*++
  106. Register hooked functions
  107. --*/
  108. HOOK_BEGIN
  109. APIHOOK_ENTRY(USER32.DLL, CreateWindowExA)
  110. APIHOOK_ENTRY(USER32.DLL, CreateWindowExW)
  111. APIHOOK_ENTRY(USER32.DLL, DialogBoxParamA)
  112. APIHOOK_ENTRY(USER32.DLL, DialogBoxParamW)
  113. APIHOOK_ENTRY(USER32.DLL, DialogBoxIndirectParamA)
  114. APIHOOK_ENTRY(USER32.DLL, DialogBoxIndirectParamW)
  115. APIHOOK_ENTRY(USER32.DLL, CreateDialogParamA)
  116. APIHOOK_ENTRY(USER32.DLL, CreateDialogParamW)
  117. APIHOOK_ENTRY(USER32.DLL, CreateDialogIndirectParamA)
  118. APIHOOK_ENTRY(USER32.DLL, CreateDialogIndirectParamW)
  119. HOOK_END
  120. IMPLEMENT_SHIM_END