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.

366 lines
13 KiB

  1. /*
  2. ** d e m a n d . h
  3. **
  4. ** Purpose: create an intelligent method of defer loading functions
  5. **
  6. ** Creators: jimsch, brimo, t-erikne
  7. ** Created: 5/15/97
  8. **
  9. ** Copyright (C) Microsoft Corp. 1997
  10. */
  11. #if !defined(__DEMAND_H) || defined(IMPLEMENT_LOADER_FUNCTIONS)
  12. #ifndef __DEMAND_H
  13. #define __DEMAND_H
  14. #endif
  15. #ifdef IMPLEMENT_LOADER_FUNCTIONS
  16. #define USE_CRITSEC
  17. #undef LOADER_FUNCTION
  18. #define LOADER_FUNCTION(ret, name, args1, args2, err, dll) \
  19. typedef ret (WINAPI * TYP_##name) args1; \
  20. extern TYP_##name VAR_##name; \
  21. ret LOADER_##name args1 \
  22. { \
  23. DemandLoad##dll(); \
  24. if (VAR_##name == LOADER_##name) return err; \
  25. return VAR_##name args2; \
  26. } \
  27. TYP_##name VAR_##name = LOADER_##name;
  28. #undef LOADER_FUNCTION_VOID
  29. #define LOADER_FUNCTION_VOID(ret, name, args1, args2, dll) \
  30. typedef ret (WINAPI * TYP_##name) args1; \
  31. extern TYP_##name VAR_##name; \
  32. ret LOADER_##name args1 \
  33. { \
  34. DemandLoad##dll(); \
  35. if (VAR_##name == LOADER_##name) return; \
  36. VAR_##name args2; \
  37. return; \
  38. } \
  39. TYP_##name VAR_##name = LOADER_##name;
  40. #else // !IMPLEMENT_LOADER_FUNCTIONS
  41. #define LOADER_FUNCTION(ret, name, args1, args2, err, dll) \
  42. typedef ret (WINAPI * TYP_##name) args1; \
  43. extern TYP_##name VAR_##name;
  44. #define LOADER_FUNCTION_VOID(ret, name, args1, args2, dll) \
  45. typedef ret (WINAPI * TYP_##name) args1; \
  46. extern TYP_##name VAR_##name;
  47. #endif // IMPLEMENT_LOADER_FUNCTIONS
  48. void InitDemandLoadedLibs();
  49. void FreeDemandLoadedLibs();
  50. /////////////////////////////////////
  51. // CRYPT32.DLL
  52. BOOL DemandLoadCrypt32(void);
  53. typedef void *HCERTSTORE;
  54. typedef const struct _CERT_CONTEXT *PCCERT_CONTEXT;
  55. typedef ULONG_PTR HCRYPTPROV;
  56. typedef struct _CERT_INFO *PCERT_INFO;
  57. LOADER_FUNCTION( BOOL, CertFreeCertificateContext,
  58. (PCCERT_CONTEXT pCertContext),
  59. (pCertContext),
  60. FALSE, Crypt32)
  61. #define CertFreeCertificateContext VAR_CertFreeCertificateContext
  62. LOADER_FUNCTION( PCCERT_CONTEXT, CertDuplicateCertificateContext,
  63. (PCCERT_CONTEXT pCertContext),
  64. (pCertContext), NULL, Crypt32)
  65. #define CertDuplicateCertificateContext VAR_CertDuplicateCertificateContext
  66. LOADER_FUNCTION( PCCERT_CONTEXT, CertFindCertificateInStore,
  67. (HCERTSTORE hCertStore, DWORD dwCertEncodingType, DWORD dwFindFlags, DWORD dwFindType, const void *pvFindPara, PCCERT_CONTEXT pPrevCertContext),
  68. (hCertStore, dwCertEncodingType, dwFindFlags, dwFindType, pvFindPara, pPrevCertContext),
  69. NULL, Crypt32)
  70. #define CertFindCertificateInStore VAR_CertFindCertificateInStore
  71. LOADER_FUNCTION( LONG, CertVerifyTimeValidity,
  72. (LPFILETIME pTimeToVerify, PCERT_INFO pCertInfo),
  73. (pTimeToVerify, pCertInfo),
  74. 1, Crypt32)
  75. #define CertVerifyTimeValidity VAR_CertVerifyTimeValidity
  76. LOADER_FUNCTION( BOOL, CertCloseStore,
  77. (HCERTSTORE hCertStore, DWORD dwFlags),
  78. (hCertStore, dwFlags),
  79. FALSE, Crypt32)
  80. #define CertOpenSystemStoreA VAR_CertOpenSystemStoreA
  81. LOADER_FUNCTION( HCERTSTORE, CertOpenSystemStoreA,
  82. (HCRYPTPROV hProv, LPCSTR szSubsystemProtocol),
  83. (hProv, szSubsystemProtocol),
  84. NULL, Crypt32)
  85. #define CertCloseStore VAR_CertCloseStore
  86. LOADER_FUNCTION( BOOL, CertGetCertificateContextProperty,
  87. (PCCERT_CONTEXT pCertContext, DWORD dwPropId, void *pvData, DWORD *pcbData),
  88. (pCertContext, dwPropId, pvData, pcbData),
  89. FALSE, Crypt32)
  90. #define CertGetCertificateContextProperty VAR_CertGetCertificateContextProperty
  91. LOADER_FUNCTION( HCERTSTORE, CertOpenStore,
  92. (LPCSTR lpszStoreProvider, DWORD dwEncodingType, HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara),
  93. (lpszStoreProvider, dwEncodingType, hCryptProv, dwFlags, pvPara),
  94. NULL, Crypt32)
  95. #define CertOpenStore VAR_CertOpenStore
  96. LOADER_FUNCTION( BOOL, CertCompareCertificate,
  97. (DWORD dwCertEncodingType, PCERT_INFO pCertId1, PCERT_INFO pCertId2),
  98. (dwCertEncodingType, pCertId1, pCertId2),
  99. FALSE, Crypt32)
  100. #define CertCompareCertificate VAR_CertCompareCertificate
  101. /////////////////////////////////////
  102. // ADVAPI32.DLL
  103. #ifndef ALGIDDEF
  104. #define ALGIDDEF
  105. typedef unsigned int ALG_ID;
  106. #endif
  107. typedef ULONG_PTR HCRYPTKEY;
  108. BOOL DemandLoadAdvApi32(void);
  109. LOADER_FUNCTION( BOOL, CryptAcquireContextA,
  110. (HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags),
  111. (phProv, pszContainer, pszProvider, dwProvType, dwFlags),
  112. FALSE, AdvApi32)
  113. #define CryptAcquireContextA VAR_CryptAcquireContextA
  114. LOADER_FUNCTION( BOOL, CryptAcquireContextW,
  115. (HCRYPTPROV *phProv, LPCTSTR pszContainer, LPCTSTR pszProvider, DWORD dwProvType, DWORD dwFlags),
  116. (phProv, pszContainer, pszProvider, dwProvType, dwFlags),
  117. FALSE, AdvApi32)
  118. #define CryptAcquireContextW VAR_CryptAcquireContextW
  119. LOADER_FUNCTION( BOOL, CryptReleaseContext,
  120. (HCRYPTPROV hProv, DWORD dwFlags),
  121. (hProv, dwFlags),
  122. FALSE, AdvApi32)
  123. #define CryptReleaseContext VAR_CryptReleaseContext
  124. LOADER_FUNCTION( BOOL, CryptMsgClose,
  125. (HCRYPTMSG hCryptMsg),
  126. (hCryptMsg),
  127. FALSE, Crypt32)
  128. #define CryptMsgClose VAR_CryptMsgClose
  129. LOADER_FUNCTION( BOOL, CryptDecodeObjectEx,
  130. (DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE * pbEncoded,
  131. DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara,
  132. void * pvStructInfo, DWORD * pcbStructInfo),
  133. (dwCertEncodingType, lpszStructType, pbEncoded, cbEncoded, dwFlags,
  134. pDecodePara, pvStructInfo, pcbStructInfo),
  135. FALSE, Crypt32)
  136. #define CryptDecodeObjectEx VAR_CryptDecodeObjectEx
  137. LOADER_FUNCTION( BOOL, CryptMsgGetParam,
  138. (HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData),
  139. (hCryptMsg, dwParamType, dwIndex, pvData, pcbData),
  140. FALSE, Crypt32)
  141. #define CryptMsgGetParam VAR_CryptMsgGetParam
  142. LOADER_FUNCTION( BOOL, CryptMsgUpdate,
  143. (HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal),
  144. (hCryptMsg, pbData, cbData, fFinal),
  145. FALSE, Crypt32)
  146. #define CryptMsgUpdate VAR_CryptMsgUpdate
  147. LOADER_FUNCTION( HCRYPTMSG, CryptMsgOpenToDecode,
  148. (DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, HCRYPTPROV hCryptProv, PCERT_INFO pRecipientInfo, PCMSG_STREAM_INFO pStreamInfo),
  149. (dwMsgEncodingType, dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo),
  150. NULL, Crypt32)
  151. #define CryptMsgOpenToDecode VAR_CryptMsgOpenToDecode
  152. LOADER_FUNCTION( BOOL, CertAddCertificateContextToStore,
  153. (HCERTSTORE hCertStore, PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition, PCCERT_CONTEXT *ppStoreContext),
  154. (hCertStore, pCertContext, dwAddDisposition, ppStoreContext),
  155. FALSE, Crypt32)
  156. #define CertAddCertificateContextToStore VAR_CertAddCertificateContextToStore
  157. /////////////////////////////////////
  158. // PSTOREC.DLL
  159. #ifndef __IEnumPStoreProviders_FWD_DEFINED__
  160. #define __IEnumPStoreProviders_FWD_DEFINED__
  161. typedef interface IEnumPStoreProviders IEnumPStoreProviders;
  162. #endif /* __IEnumPStoreProviders_FWD_DEFINED__ */
  163. #ifndef __IPStore_FWD_DEFINED__
  164. #define __IPStore_FWD_DEFINED__
  165. typedef interface IPStore IPStore;
  166. #endif /* __IPStore_FWD_DEFINED__ */
  167. typedef GUID PST_PROVIDERID;
  168. BOOL DemandLoadPStoreC();
  169. LOADER_FUNCTION( HRESULT, PStoreCreateInstance,
  170. (IPStore __RPC_FAR *__RPC_FAR *ppProvider, PST_PROVIDERID __RPC_FAR *pProviderID, void __RPC_FAR *pReserved, DWORD dwFlags),
  171. (ppProvider, pProviderID, pReserved, dwFlags),
  172. E_FAIL, PStoreC)
  173. #define PStoreCreateInstance VAR_PStoreCreateInstance
  174. LOADER_FUNCTION( HRESULT, PStoreEnumProviders,
  175. (DWORD dwFlags, IEnumPStoreProviders __RPC_FAR *__RPC_FAR *ppenum),
  176. (dwFlags, ppenum),
  177. E_FAIL, PStoreC)
  178. #define PStoreEnumProviders VAR_PStoreEnumProviders
  179. /////////////////////////////////////
  180. // CRYPTDLG.DLL
  181. BOOL DemandLoadCryptDlg();
  182. LOADER_FUNCTION( DWORD, GetFriendlyNameOfCertA,
  183. (PCCERT_CONTEXT pccert, LPSTR pchBuffer, DWORD cchBuffer),
  184. (pccert, pchBuffer, cchBuffer),
  185. 0, CryptDlg)
  186. #define GetFriendlyNameOfCertA VAR_GetFriendlyNameOfCertA
  187. LOADER_FUNCTION( BOOL, CertViewPropertiesA,
  188. (PCERT_VIEWPROPERTIES_STRUCT_A pCertViewInfo),
  189. (pCertViewInfo),
  190. FALSE, CryptDlg)
  191. #define CertViewPropertiesA VAR_CertViewPropertiesA
  192. /////////////////////////////////////
  193. // WINTRUST.DLL
  194. BOOL DemandLoadWinTrust();
  195. LOADER_FUNCTION( LONG, WinVerifyTrust,
  196. (HWND hwnd, GUID *ActionID, LPVOID ActionData),
  197. (hwnd, ActionID, ActionData),
  198. 0, WinTrust)
  199. #define WinVerifyTrust VAR_WinVerifyTrust
  200. /////////////////////////////////////
  201. // VERSION.DLL
  202. BOOL DemandLoadVersion(void);
  203. LOADER_FUNCTION( DWORD, GetFileVersionInfoSizeA,
  204. (LPSTR lptstrFileName, LPDWORD lpdwHandle),
  205. (lptstrFileName, lpdwHandle),
  206. 0, Version)
  207. #define GetFileVersionInfoSizeA VAR_GetFileVersionInfoSizeA
  208. LOADER_FUNCTION( BOOL, GetFileVersionInfoA,
  209. (LPSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData),
  210. (lptstrFilename, dwHandle, dwLen, lpData),
  211. FALSE, Version)
  212. #define GetFileVersionInfoA VAR_GetFileVersionInfoA
  213. LOADER_FUNCTION( BOOL, VerQueryValueA,
  214. (const LPVOID pBlock, LPSTR lpSubBlock, LPVOID * lplpBuffer, PUINT puLen),
  215. (pBlock, lpSubBlock, lplpBuffer, puLen),
  216. FALSE, Version)
  217. #define VerQueryValueA VAR_VerQueryValueA
  218. LOADER_FUNCTION( DWORD, GetFileVersionInfoSizeW,
  219. (LPTSTR lptstrFileName, LPDWORD lpdwHandle),
  220. (lptstrFileName, lpdwHandle),
  221. 0, Version)
  222. #define GetFileVersionInfoSizeW VAR_GetFileVersionInfoSizeW
  223. LOADER_FUNCTION( BOOL, GetFileVersionInfoW,
  224. (LPTSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData),
  225. (lptstrFilename, dwHandle, dwLen, lpData),
  226. FALSE, Version)
  227. #define GetFileVersionInfoW VAR_GetFileVersionInfoW
  228. LOADER_FUNCTION( BOOL, VerQueryValueW,
  229. (const LPVOID pBlock, LPTSTR lpSubBlock, LPVOID * lplpBuffer, PUINT puLen),
  230. (pBlock, lpSubBlock, lplpBuffer, puLen),
  231. FALSE, Version)
  232. #define VerQueryValueW VAR_VerQueryValueW
  233. /////////////////////////////////////
  234. // URLMON.DLL
  235. BOOL DemandLoadURLMON();
  236. LOADER_FUNCTION( HRESULT, ObtainUserAgentString,
  237. (DWORD dwOption, LPSTR pszUAOut, DWORD* cbSize),
  238. (dwOption, pszUAOut, cbSize),
  239. E_FAIL, URLMON)
  240. #define ObtainUserAgentString VAR_ObtainUserAgentString
  241. // IMM32.DLL
  242. BOOL DemandLoadImm32(void);
  243. LOADER_FUNCTION(HIMC, ImmAssociateContext,
  244. (HWND hWnd, HIMC hIMC),
  245. (hWnd, hIMC),
  246. 0, Imm32)
  247. #define ImmAssociateContext VAR_ImmAssociateContext
  248. LOADER_FUNCTION(HIMC, ImmGetContext,
  249. (HWND hWnd),
  250. (hWnd),
  251. 0, Imm32)
  252. #define ImmGetContext VAR_ImmGetContext
  253. LOADER_FUNCTION(LONG, ImmGetCompositionStringW,
  254. (HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen),
  255. (hIMC, dwIndex, lpBuf, dwBufLen),
  256. 0, Imm32)
  257. #define ImmGetCompositionStringW VAR_ImmGetCompositionStringW
  258. LOADER_FUNCTION(BOOL, ImmReleaseContext,
  259. (HWND hWnd, HIMC hIMC),
  260. (hWnd, hIMC),
  261. 0, Imm32)
  262. #define ImmReleaseContext VAR_ImmReleaseContext
  263. // Wininet.DLL
  264. BOOL DemandLoadWininet(void);
  265. LOADER_FUNCTION(BOOL, InternetCanonicalizeUrlW,
  266. (LPCWSTR lpszUrl, LPWSTR lpszBuffer, LPDWORD lpdwBufferLength, DWORD dwFlags),
  267. (lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags),
  268. FALSE, Wininet)
  269. #define InternetCanonicalizeUrlW VAR_InternetCanonicalizeUrlW
  270. LOADER_FUNCTION(BOOL, InternetGetConnectedState,
  271. (LPDWORD lpdwFlags, DWORD dwReserved),
  272. (lpdwFlags, dwReserved),
  273. FALSE, Wininet)
  274. #define InternetGetConnectedState VAR_InternetGetConnectedState
  275. ///////////////////////////////////////////////////////////////////////////////
  276. // SHLWAPI.DLL
  277. HINSTANCE DemandLoadShlwapi();
  278. ///////////////////////////////////////////////////////////////////////////////
  279. // Plus UI wrapper functions for WinHelp and HtmlHelp functions. If 5.0 (IE5)
  280. // version of Shlwapi.dll is available then its version of the functions are
  281. // used. Default is to system versions. If runnint WinNT5.0 or greater then
  282. // cross codepage is used.
  283. //
  284. // Implementation of these functions are in the entry.c file
  285. ///////////////////////////////////////////////////////////////////////////////
  286. BOOL WinHelpWrap(HWND hWndCaller, LPCTSTR pwszHelpFile, UINT uCommand, DWORD_PTR dwData);
  287. #define WABWinHelp WinHelpWrap
  288. HWND HtmlHelpWrap(HWND hWndCaller, LPCTSTR pwszHelpFile, UINT uCommand, DWORD_PTR dwData);
  289. #define WABHtmlHelp HtmlHelpWrap
  290. #endif // include once