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.

293 lines
15 KiB

  1. //
  2. // delay.cpp
  3. //
  4. // Delay load imported functions for perf.
  5. //
  6. #include "private.h"
  7. #include "globals.h"
  8. #include "ciccs.h"
  9. extern CCicCriticalSectionStatic g_cs;
  10. FARPROC GetFn(HINSTANCE *phInst, TCHAR *pchLib, TCHAR *pchFunc)
  11. {
  12. if (*phInst == 0)
  13. {
  14. EnterCriticalSection(g_cs);
  15. // need to check again after entering crit sec
  16. if (*phInst == 0)
  17. {
  18. *phInst = LoadSystemLibrary(pchLib);
  19. }
  20. LeaveCriticalSection(g_cs);
  21. if (*phInst == 0)
  22. {
  23. Assert(0);
  24. return NULL;
  25. }
  26. }
  27. return GetProcAddress(*phInst, pchFunc);
  28. }
  29. #define DELAYLOAD(_hInst, _DllName, _CallConv, _FuncName, _Args1, _Args2, _RetType, _ErrVal) \
  30. _RetType _CallConv _FuncName _Args1 \
  31. { \
  32. static FARPROC pfn = NULL; \
  33. \
  34. if (pfn == NULL || _hInst == NULL) \
  35. { \
  36. pfn = GetFn(&_hInst, #_DllName, #_FuncName); \
  37. \
  38. if (pfn == NULL) \
  39. { \
  40. Assert(0); \
  41. return (_RetType) _ErrVal; \
  42. } \
  43. } \
  44. \
  45. return ((_RetType (_CallConv *)_Args1) (pfn)) _Args2; \
  46. }
  47. //
  48. // imm32.dll
  49. //
  50. HINSTANCE g_hImm32 = 0;
  51. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetDescriptionA, (HKL hKL, LPSTR psz, UINT uBufLen), (hKL, psz, uBufLen), UINT, 0)
  52. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetDescriptionW, (HKL hKL, LPWSTR psz, UINT uBufLen), (hKL, psz, uBufLen), UINT, 0)
  53. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetIMEFileNameA, (HKL hKL, LPSTR lpszFileName, UINT uBufLen), (hKL, lpszFileName, uBufLen), UINT, 0)
  54. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetIMEFileNameW, (HKL hKL, LPWSTR lpszFileName, UINT uBufLen), (hKL, lpszFileName, uBufLen), UINT, 0)
  55. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetDefaultIMEWnd, (HWND hWnd), (hWnd), HWND, 0)
  56. #ifdef UNUSED_IMM32_APIS
  57. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmReleaseContext, (HWND hWnd, HIMC hIMC), (hWnd, hIMC), BOOL, FALSE)
  58. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmNotifyIME, (HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue), (hIMC, dwAction, dwIndex, dwValue), BOOL, FALSE)
  59. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetConversionStatus, (HIMC hIMC, DWORD dw1, DWORD dw2), (hIMC, dw1, dw2), BOOL, FALSE)
  60. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetConversionStatus, (HIMC hIMC, LPDWORD pdw1, LPDWORD pdw2), (hIMC, pdw1, pdw2), BOOL, FALSE)
  61. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetProperty, (HKL hKL, DWORD dw), (hKL, dw), DWORD, 0)
  62. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetOpenStatus, (HIMC hIMC), (hIMC), BOOL, FALSE)
  63. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetContext, (HWND hWnd), (hWnd), HIMC, 0)
  64. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetOpenStatus, (HIMC hIMC, BOOL f), (hIMC, f), BOOL, FALSE)
  65. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmInstallIMEA, (LPCSTR lpszIMEFileName, LPCSTR lpszLayoutText), (lpszIMEFileName, lpszLayoutText), HKL, 0)
  66. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmCreateIMCC, (DWORD dw), (dw), HIMCC, FALSE)
  67. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmIsUIMessageA, (HWND hWnd, UINT u, WPARAM wParam, LPARAM lParam), (hWnd, u, wParam, lParam), BOOL, FALSE)
  68. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmIsUIMessageW, (HWND hWnd, UINT u, WPARAM wParam, LPARAM lParam), (hWnd, u, wParam, lParam), BOOL, FALSE)
  69. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetVirtualKey, (HWND hWnd), (hWnd), UINT, VK_PROCESSKEY)
  70. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetCompositionWindow, (HIMC hIMC, LPCOMPOSITIONFORM pCF), (hIMC, pCF), BOOL, FALSE)
  71. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmConfigureIMEA, (HKL hKL, HWND hWnd, DWORD dw, LPVOID pv), (hKL, hWnd, dw, pv), BOOL, FALSE)
  72. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmConfigureIMEW, (HKL hKL, HWND hWnd, DWORD dw, LPVOID pv), (hKL, hWnd, dw, pv), BOOL, FALSE)
  73. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmDestroyContext, (HIMC hIMC), (hIMC), BOOL, FALSE)
  74. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmAssociateContext, (HWND hWnd, HIMC hIMC), (hWnd, hIMC), HIMC, 0)
  75. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmEscapeA, (HKL hKL, HIMC hIMC, UINT u, LPVOID pv), (hKL, hIMC, u, pv), LRESULT, 0)
  76. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmEscapeW, (HKL hKL, HIMC hIMC, UINT u, LPVOID pv), (hKL, hIMC, u, pv), LRESULT, 0)
  77. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmIsIME, (HKL hKL), (hKL), BOOL, FALSE)
  78. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmCreateContext, (void), (), HIMC, 0)
  79. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCompositionFontA, (HIMC hIMC, LPLOGFONTA plf), (hIMC, plf), BOOL, FALSE)
  80. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCompositionFontW, (HIMC hIMC, LPLOGFONTW plf), (hIMC, plf), BOOL, FALSE)
  81. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCandidateWindow, (HIMC hIMC, DWORD dw, LPCANDIDATEFORM pCF), (hIMC, dw, pCF), BOOL, FALSE)
  82. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCandidateListA, (HIMC hIMC, DWORD dwIndex, LPCANDIDATELIST lpCandList, DWORD dwBufLen), (hIMC, dwIndex, lpCandList, dwBufLen), DWORD, 0)
  83. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCandidateListW, (HIMC hIMC, DWORD dwIndex, LPCANDIDATELIST lpCandList, DWORD dwBufLen), (hIMC, dwIndex, lpCandList, dwBufLen), DWORD, 0)
  84. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCandidateListCountA, (HIMC hIMC, LPDWORD lpdwListCount), (hIMC, lpdwListCount), DWORD, 0)
  85. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCandidateListCountW, (HIMC hIMC, LPDWORD lpdwListCount), (hIMC, lpdwListCount), DWORD, 0)
  86. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCompositionStringA, (HIMC hIMC, DWORD dw1, LPVOID pv, DWORD dw2), (hIMC, dw1, pv, dw2), LONG, 0)
  87. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCompositionStringW, (HIMC hIMC, DWORD dw1, LPVOID pv, DWORD dw2), (hIMC, dw1, pv, dw2), LONG, 0)
  88. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetCompositionWindow, (HIMC hIMC, LPCOMPOSITIONFORM pCF), (hIMC, pCF), BOOL, FALSE)
  89. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetConversionListA, (HKL hKL, HIMC hIMC, LPCSTR psz, LPCANDIDATELIST pCL, DWORD dwBufLen, UINT uFlag), (hKL, hIMC, psz, pCL, dwBufLen, uFlag), DWORD, 0)
  90. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetConversionListW, (HKL hKL, HIMC hIMC, LPCWSTR psz, LPCANDIDATELIST pCL, DWORD dwBufLen, UINT uFlag), (hKL, hIMC, psz, pCL, dwBufLen, uFlag), DWORD, 0)
  91. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetStatusWindowPos, (HIMC hIMC, LPPOINT lpptPos), (hIMC, lpptPos), BOOL, FALSE)
  92. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetStatusWindowPos, (HIMC hIMC, LPPOINT lpptPos), (hIMC, lpptPos), BOOL, FALSE)
  93. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetIMCCSize, (HIMCC hIMCC), (hIMCC), DWORD, 0)
  94. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmReSizeIMCC, (HIMCC hIMCC, DWORD dw), (hIMCC, dw), HIMCC, 0)
  95. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmUnlockIMCC, (HIMCC hIMCC), (hIMCC), BOOL, FALSE)
  96. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmLockIMCC, (HIMCC hIMCC), (hIMCC), LPVOID, NULL)
  97. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmDestroyIMCC, (HIMCC hIMCC), (hIMCC), HIMCC, hIMCC)
  98. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmUnlockIMC, (HIMC hIMC), (hIMC), BOOL, FALSE)
  99. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmLockIMC, (HIMC hIMC), (hIMC), LPINPUTCONTEXT, NULL)
  100. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetCompositionStringA, (HIMC hIMC, DWORD dwIndex, LPCVOID lpComp, DWORD dw1, LPCVOID lpRead, DWORD dw2), (hIMC, dwIndex, lpComp, dw1, lpRead, dw2), BOOL, FALSE)
  101. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetCompositionStringW, (HIMC hIMC, DWORD dwIndex, LPCVOID lpComp, DWORD dw1, LPCVOID lpRead, DWORD dw2), (hIMC, dwIndex, lpComp, dw1, lpRead, dw2), BOOL, FALSE)
  102. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetCompositionFontA, (HIMC hIMC, LPLOGFONTA plf), (hIMC, plf), BOOL, FALSE)
  103. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetCompositionFontW, (HIMC hIMC, LPLOGFONTW plf), (hIMC, plf), BOOL, FALSE)
  104. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSetCandidateWindow, (HIMC hIMC, LPCANDIDATEFORM pCF), (hIMC, pCF), BOOL, FALSE)
  105. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmRegisterWordA, (HKL hKL, LPCSTR lpszReading, DWORD dw, LPCSTR lpszRegister), (hKL, lpszReading, dw, lpszRegister), BOOL, FALSE)
  106. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmRegisterWordW, (HKL hKL, LPCWSTR lpszReading, DWORD dw, LPCWSTR lpszRegister), (hKL, lpszReading, dw, lpszRegister), BOOL, FALSE)
  107. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmUnregisterWordA, (HKL hKL, LPCSTR lpszReading, DWORD dw, LPCSTR lpszUnregister), (hKL, lpszReading, dw, lpszUnregister), BOOL, FALSE)
  108. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmUnregisterWordW, (HKL hKL, LPCWSTR lpszReading, DWORD dw, LPCWSTR lpszUnregister), (hKL, lpszReading, dw, lpszUnregister), BOOL, FALSE)
  109. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetRegisterWordStyleA, (HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf), (hKL, nItem, lpStyleBuf), UINT, 0)
  110. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetRegisterWordStyleW, (HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf), (hKL, nItem, lpStyleBuf), UINT, 0)
  111. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmSimulateHotKey, (HWND hWnd, DWORD dwHotKeyID), (hWnd, dwHotKeyID), BOOL, FALSE)
  112. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetGuideLineA, (HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen), (hIMC, dwIndex, lpBuf, dwBufLen), DWORD, 0)
  113. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetGuideLineW, (HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen), (hIMC, dwIndex, lpBuf, dwBufLen), DWORD, 0)
  114. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmAssociateContextEx, (HWND hWnd, HIMC hIMC, DWORD dwFlags), (hWnd, hIMC, dwFlags), BOOL, FALSE)
  115. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmDisableIME, (DWORD dwId), (dwId), BOOL, FALSE)
  116. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetImeMenuItemsA, (HIMC hIMC, DWORD dwFlags, DWORD dwType, IMEMENUITEMINFOA *pImeParentMenu, IMEMENUITEMINFOA *pImeMenu, DWORD dwSize), (hIMC, dwFlags, dwType, pImeParentMenu, pImeMenu, dwSize), DWORD, 0)
  117. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmGetImeMenuItemsW, (HIMC hIMC, DWORD dwFlags, DWORD dwType, IMEMENUITEMINFOW *pImeParentMenu, IMEMENUITEMINFOW *pImeMenu, DWORD dwSize), (hIMC, dwFlags, dwType, pImeParentMenu, pImeMenu, dwSize), DWORD, 0)
  118. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmRequestMessageA, (HIMC hIMC, WPARAM wParam, LPARAM lParam), (hIMC, wParam, lParam), LRESULT, 0)
  119. DELAYLOAD(g_hImm32, imm32.dll, WINAPI, ImmRequestMessageW, (HIMC hIMC, WPARAM wParam, LPARAM lParam), (hIMC, wParam, lParam), LRESULT, 0)
  120. #endif // UNUSED_IMM32_APIS
  121. //
  122. // shell32
  123. //
  124. HINSTANCE g_hShell32 = 0;
  125. BOOL WINAPI Internal_Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATA pnid)
  126. {
  127. static FARPROC pfn = NULL;
  128. if (pfn == NULL || g_hShell32 == NULL)
  129. {
  130. pfn = GetFn(&g_hShell32, "shell32.dll", "Shell_NotifyIconA");
  131. if (pfn == NULL)
  132. {
  133. Assert(0);
  134. return FALSE;
  135. }
  136. }
  137. return ((BOOL (WINAPI *)(DWORD dwMessage, PNOTIFYICONDATA pnid))(pfn))(dwMessage, pnid);
  138. }
  139. BOOL WINAPI Internal_Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
  140. {
  141. static FARPROC pfn = NULL;
  142. if (pfn == NULL || g_hShell32 == NULL)
  143. {
  144. pfn = GetFn(&g_hShell32, "shell32.dll", "Shell_NotifyIconW");
  145. if (pfn == NULL)
  146. {
  147. Assert(0);
  148. return FALSE;
  149. }
  150. }
  151. return ((BOOL (WINAPI *)(DWORD dwMessage, PNOTIFYICONDATAW pnid))(pfn))(dwMessage, pnid);
  152. }
  153. BOOL WINAPI Internal_Shell_SHAppBarMessage(DWORD dwMessage, PAPPBARDATA pabd)
  154. {
  155. static FARPROC pfn = NULL;
  156. if (pfn == NULL || g_hShell32 == NULL)
  157. {
  158. pfn = GetFn(&g_hShell32, "shell32.dll", "SHAppBarMessage");
  159. if (pfn == NULL)
  160. {
  161. Assert(0);
  162. return FALSE;
  163. }
  164. }
  165. return ((BOOL (WINAPI *)(DWORD dwMessage,PAPPBARDATA pabd ))(pfn))(dwMessage, pabd);
  166. }
  167. //
  168. // ole32
  169. //
  170. HINSTANCE g_hOle32 = 0;
  171. extern "C" HRESULT WINAPI TF_CreateCategoryMgr(ITfCategoryMgr **ppCategoryMgr);
  172. HRESULT STDAPICALLTYPE Internal_CoCreateInstance(REFCLSID rclsid, LPUNKNOWN punkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv)
  173. {
  174. static FARPROC pfn = NULL;
  175. // Issue: once library is clean, it can call these directly
  176. if (IsEqualCLSID(rclsid, CLSID_TF_CategoryMgr))
  177. {
  178. return TF_CreateCategoryMgr((ITfCategoryMgr **)ppv);
  179. }
  180. else if (IsEqualCLSID(rclsid, CLSID_TF_DisplayAttributeMgr))
  181. {
  182. return TF_CreateDisplayAttributeMgr((ITfDisplayAttributeMgr **)ppv);
  183. }
  184. if (pfn == NULL || g_hOle32 == NULL)
  185. {
  186. pfn = GetFn(&g_hOle32, "ole32.dll", "CoCreateInstance");
  187. if (pfn == NULL)
  188. {
  189. Assert(0);
  190. if (ppv != NULL)
  191. {
  192. *ppv = NULL;
  193. }
  194. return E_FAIL;
  195. }
  196. }
  197. return ((HRESULT (STDAPICALLTYPE *)(REFCLSID rclsid, LPUNKNOWN punkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv))(pfn))(rclsid, punkOuter, dwClsContext, riid, ppv);
  198. }
  199. HRESULT STDAPICALLTYPE Internal_CoInitialize(LPVOID pvReserved)
  200. {
  201. static FARPROC pfn = NULL;
  202. if (pfn == NULL || g_hOle32 == NULL)
  203. {
  204. pfn = GetFn(&g_hOle32, "ole32.dll", "CoInitialize");
  205. if (pfn == NULL)
  206. {
  207. Assert(0);
  208. return E_FAIL;
  209. }
  210. }
  211. return ((HRESULT (STDAPICALLTYPE *)(LPVOID pvReserved))(pfn))(pvReserved);
  212. }
  213. HRESULT STDAPICALLTYPE Internal_CoUninitialize()
  214. {
  215. static FARPROC pfn = NULL;
  216. if (pfn == NULL || g_hOle32 == NULL)
  217. {
  218. pfn = GetFn(&g_hOle32, "ole32.dll", "CoUninitialize");
  219. if (pfn == NULL)
  220. {
  221. Assert(0);
  222. return E_FAIL;
  223. }
  224. }
  225. return ((HRESULT (STDAPICALLTYPE *)())(pfn))();
  226. }
  227. void STDAPICALLTYPE Internal_CoTaskMemFree(void *pv)
  228. {
  229. static FARPROC pfn = NULL;
  230. if (pfn == NULL || g_hOle32 == NULL)
  231. {
  232. pfn = GetFn(&g_hOle32, "ole32.dll", "CoTaskMemFree");
  233. if (pfn == NULL)
  234. {
  235. Assert(0);
  236. return;
  237. }
  238. }
  239. return ((void (STDAPICALLTYPE *)(void *pv))(pfn))(pv);
  240. }
  241. //
  242. // oleacc
  243. //
  244. HINSTANCE g_hOleAcc = 0;
  245. DELAYLOAD(g_hOleAcc, oleacc.dll, WINAPI, CreateStdAccessibleObject, (HWND hwnd, LONG l, REFIID riid, void **ppv), (hwnd, l, riid, ppv), HRESULT, 0)
  246. DELAYLOAD(g_hOleAcc, oleacc.dll, WINAPI, LresultFromObject, (REFIID riid, WPARAM wParam, IUnknown *punk), (riid, wParam, punk), LRESULT, 0)