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.

773 lines
25 KiB

  1. // --------------------------------------------------------------------------------
  2. // Demand.cpp
  3. // Written By: jimsch, brimo, t-erikne (bastardized by sbailey)
  4. // --------------------------------------------------------------------------------
  5. // W4 stuff
  6. #pragma warning(disable: 4201) // nameless struct/union
  7. #pragma warning(disable: 4514) // unreferenced inline function removed
  8. // --------------------------------------------------------------------------------
  9. // Includes
  10. // --------------------------------------------------------------------------------
  11. #include <windows.h>
  12. #include "myassert.h"
  13. #define IMPLEMENT_LOADER_FUNCTIONS
  14. #include "demand.h"
  15. // --------------------------------------------------------------------------------
  16. // CRIT_GET_PROC_ADDR
  17. // --------------------------------------------------------------------------------
  18. #define CRIT_GET_PROC_ADDR(h, fn, temp) \
  19. temp = (TYP_##fn) GetProcAddress(h, #fn); \
  20. if (temp) \
  21. VAR_##fn = temp; \
  22. else \
  23. { \
  24. AssertSz(0, VAR_##fn" failed to load"); \
  25. goto error; \
  26. }
  27. // --------------------------------------------------------------------------------
  28. // RESET
  29. // --------------------------------------------------------------------------------
  30. #define RESET(fn) VAR_##fn = LOADER_##fn;
  31. // --------------------------------------------------------------------------------
  32. // GET_PROC_ADDR
  33. // --------------------------------------------------------------------------------
  34. #define GET_PROC_ADDR(h, fn) \
  35. VAR_##fn = (TYP_##fn) GetProcAddress(h, #fn); \
  36. Assert(VAR_##fn != NULL);
  37. // --------------------------------------------------------------------------------
  38. // GET_PROC_ADDR_ORDINAL
  39. // --------------------------------------------------------------------------------
  40. #define GET_PROC_ADDR_ORDINAL(h, fn, ord) \
  41. VAR_##fn = (TYP_##fn) GetProcAddress(h, MAKEINTRESOURCE(ord)); \
  42. Assert(VAR_##fn != NULL);
  43. // --------------------------------------------------------------------------------
  44. // GET_PROC_ADDR3
  45. // --------------------------------------------------------------------------------
  46. #define GET_PROC_ADDR3(h, fn, varname) \
  47. VAR_##varname = (TYP_##varname) GetProcAddress(h, #fn); \
  48. Assert(VAR_##varname != NULL);
  49. // --------------------------------------------------------------------------------
  50. // Static Globals
  51. // --------------------------------------------------------------------------------
  52. static HMODULE s_hCrypt = 0;
  53. static HMODULE s_hCryptDlg = 0;
  54. static HMODULE s_hWinTrust = 0;
  55. #if 0
  56. static HMODULE s_hWinINET = 0;
  57. static HMODULE s_hShell32 = 0;
  58. static HMODULE s_hOleAut32 = 0;
  59. static HMODULE s_hComDlg32 = 0;
  60. static HMODULE s_hVersion = 0;
  61. static HMODULE s_hUrlmon = 0;
  62. static HMODULE s_hShDocVw = 0;
  63. static HMODULE s_hInetCPL = 0;
  64. static HMODULE s_hMSO9 = 0;
  65. static HMODULE s_hWinMM = 0;
  66. static HMODULE s_hRichEdit = 0;
  67. static HMODULE s_hMLANG = 0;
  68. static HMODULE s_hWSOCK = 0;
  69. static HMODULE s_hPstoreC = 0;
  70. static HMODULE s_hRAS = 0;
  71. static HMODULE s_hAdvApi = 0;
  72. #endif // 0
  73. static CRITICAL_SECTION g_csDefLoad = {0};
  74. // --------------------------------------------------------------------------------
  75. // InitDemandLoadedLibs
  76. // --------------------------------------------------------------------------------
  77. void InitDemandLoadedLibs(void)
  78. {
  79. InitializeCriticalSection(&g_csDefLoad);
  80. }
  81. // --------------------------------------------------------------------------------
  82. // FreeDemandLoadedLibs
  83. // --------------------------------------------------------------------------------
  84. void FreeDemandLoadedLibs(void)
  85. {
  86. EnterCriticalSection(&g_csDefLoad);
  87. if (s_hCrypt) FreeLibrary(s_hCrypt);
  88. if (s_hCryptDlg) FreeLibrary(s_hCryptDlg);
  89. if (s_hWinTrust) FreeLibrary(s_hWinTrust);
  90. #if 0
  91. FreeLibrary(s_hWinINET);
  92. FreeLibrary(s_hWSOCK);
  93. FreeLibrary(s_hShell32);
  94. FreeLibrary(s_hOleAut32);
  95. FreeLibrary(s_hComDlg32);
  96. FreeLibrary(s_hVersion);
  97. FreeLibrary(s_hUrlmon);
  98. FreeLibrary(s_hMLANG);
  99. FreeLibrary(s_hShDocVw);
  100. FreeLibrary(s_hInetCPL);
  101. FreeLibrary(s_hMSO9);
  102. FreeLibrary(s_hWinMM);
  103. FreeLibrary(s_hRichEdit);
  104. FreeLibrary(s_hPstoreC);
  105. FreeLibrary(s_hRAS);
  106. FreeLibrary(s_hAdvApi);
  107. #endif // 0
  108. LeaveCriticalSection(&g_csDefLoad);
  109. DeleteCriticalSection(&g_csDefLoad);
  110. }
  111. // --------------------------------------------------------------------------------
  112. // DemandLoadCrypt32
  113. // --------------------------------------------------------------------------------
  114. BOOL DemandLoadCrypt32(void)
  115. {
  116. BOOL fRet = TRUE;
  117. EnterCriticalSection(&g_csDefLoad);
  118. if (0 == s_hCrypt)
  119. {
  120. s_hCrypt = LoadLibrary("CRYPT32.DLL");
  121. AssertSz((BOOL)s_hCrypt, TEXT("LoadLibrary failed on CRYPT32.DLL"));
  122. if (0 == s_hCrypt)
  123. fRet = FALSE;
  124. else
  125. {
  126. GET_PROC_ADDR(s_hCrypt, CertRDNValueToStrA);
  127. GET_PROC_ADDR(s_hCrypt, CertAddCertificateContextToStore)
  128. GET_PROC_ADDR(s_hCrypt, CertGetIssuerCertificateFromStore)
  129. GET_PROC_ADDR(s_hCrypt, CertEnumCertificatesInStore)
  130. GET_PROC_ADDR(s_hCrypt, CertFreeCertificateContext)
  131. GET_PROC_ADDR(s_hCrypt, CertDuplicateCertificateContext)
  132. GET_PROC_ADDR(s_hCrypt, CertFindCertificateInStore)
  133. GET_PROC_ADDR(s_hCrypt, CertVerifyTimeValidity)
  134. GET_PROC_ADDR(s_hCrypt, CertCompareCertificate)
  135. GET_PROC_ADDR(s_hCrypt, CertOpenStore)
  136. GET_PROC_ADDR(s_hCrypt, CertDuplicateStore)
  137. GET_PROC_ADDR(s_hCrypt, CertCloseStore)
  138. GET_PROC_ADDR(s_hCrypt, CertGetCertificateContextProperty)
  139. GET_PROC_ADDR(s_hCrypt, CertGetSubjectCertificateFromStore)
  140. GET_PROC_ADDR(s_hCrypt, CryptDecodeObject)
  141. GET_PROC_ADDR(s_hCrypt, CryptDecodeObjectEx)
  142. GET_PROC_ADDR(s_hCrypt, CertFindRDNAttr)
  143. GET_PROC_ADDR(s_hCrypt, CryptMsgOpenToEncode)
  144. GET_PROC_ADDR(s_hCrypt, CryptMsgOpenToDecode)
  145. GET_PROC_ADDR(s_hCrypt, CryptMsgControl)
  146. GET_PROC_ADDR(s_hCrypt, CryptMsgUpdate)
  147. GET_PROC_ADDR(s_hCrypt, CryptMsgGetParam)
  148. GET_PROC_ADDR(s_hCrypt, CryptMsgClose)
  149. GET_PROC_ADDR(s_hCrypt, CryptEncodeObject)
  150. GET_PROC_ADDR(s_hCrypt, CryptEncodeObjectEx)
  151. GET_PROC_ADDR(s_hCrypt, CertAddEncodedCRLToStore)
  152. GET_PROC_ADDR(s_hCrypt, CertEnumCRLsInStore)
  153. GET_PROC_ADDR(s_hCrypt, CertFindExtension)
  154. GET_PROC_ADDR(s_hCrypt, CertStrToNameW)
  155. GET_PROC_ADDR(s_hCrypt, CertAddEncodedCertificateToStore)
  156. GET_PROC_ADDR(s_hCrypt, CertAddStoreToCollection)
  157. }
  158. }
  159. LeaveCriticalSection(&g_csDefLoad);
  160. return fRet;
  161. }
  162. // --------------------------------------------------------------------------------
  163. // DemandLoadCryptDlg
  164. // --------------------------------------------------------------------------------
  165. BOOL DemandLoadCryptDlg(void)
  166. {
  167. BOOL fRet = TRUE;
  168. EnterCriticalSection(&g_csDefLoad);
  169. if (0 == s_hCryptDlg)
  170. {
  171. s_hCryptDlg = LoadLibrary("CRYPTDLG.DLL");
  172. AssertSz((BOOL)s_hCryptDlg, TEXT("LoadLibrary failed on CRYPTDLG.DLL"));
  173. if (0 == s_hCryptDlg)
  174. fRet = FALSE;
  175. else
  176. {
  177. GET_PROC_ADDR(s_hCryptDlg, CertViewPropertiesA)
  178. GET_PROC_ADDR(s_hCryptDlg, GetFriendlyNameOfCertA)
  179. GET_PROC_ADDR(s_hCryptDlg, CertSelectCertificateA)
  180. }
  181. }
  182. LeaveCriticalSection(&g_csDefLoad);
  183. return fRet;
  184. }
  185. // --------------------------------------------------------------------------------
  186. // DemandLoadWinTrust
  187. // --------------------------------------------------------------------------------
  188. BOOL DemandLoadWinTrust(void)
  189. {
  190. BOOL fRet = TRUE;
  191. EnterCriticalSection(&g_csDefLoad);
  192. if (0 == s_hWinTrust)
  193. {
  194. s_hWinTrust = LoadLibrary("WINTRUST.DLL");
  195. AssertSz((BOOL)s_hWinTrust, TEXT("LoadLibrary failed on WINTRUST.DLL"));
  196. if (0 == s_hWinTrust)
  197. fRet = FALSE;
  198. else
  199. {
  200. GET_PROC_ADDR(s_hWinTrust, WinVerifyTrust)
  201. }
  202. }
  203. LeaveCriticalSection(&g_csDefLoad);
  204. return fRet;
  205. }
  206. #if 0
  207. // --------------------------------------------------------------------------------
  208. // DemandLoadWinINET
  209. // --------------------------------------------------------------------------------
  210. BOOL DemandLoadWinINET(void)
  211. {
  212. BOOL fRet = TRUE;
  213. EnterCriticalSection(&g_csDefLoad);
  214. if (0 == s_hWinINET)
  215. {
  216. s_hWinINET = LoadLibrary("WININET.DLL");
  217. AssertSz((BOOL)s_hWinINET, TEXT("LoadLibrary failed on WININET.DLL"));
  218. if (0 == s_hWinINET)
  219. fRet = FALSE;
  220. else
  221. {
  222. GET_PROC_ADDR(s_hWinINET, RetrieveUrlCacheEntryFileA)
  223. GET_PROC_ADDR(s_hWinINET, UnlockUrlCacheEntryFileA)
  224. GET_PROC_ADDR(s_hWinINET, InternetQueryOptionA)
  225. GET_PROC_ADDR(s_hWinINET, InternetSetOptionA)
  226. GET_PROC_ADDR(s_hWinINET, InternetDialA)
  227. GET_PROC_ADDR(s_hWinINET, InternetHangUp)
  228. GET_PROC_ADDR(s_hWinINET, InternetGetConnectedStateExA)
  229. GET_PROC_ADDR(s_hWinINET, InternetCombineUrlA)
  230. GET_PROC_ADDR(s_hWinINET, InternetCrackUrlA)
  231. GET_PROC_ADDR(s_hWinINET, InternetCloseHandle)
  232. GET_PROC_ADDR(s_hWinINET, InternetReadFile)
  233. GET_PROC_ADDR(s_hWinINET, InternetConnectA)
  234. GET_PROC_ADDR(s_hWinINET, InternetOpenA)
  235. GET_PROC_ADDR(s_hWinINET, HttpQueryInfoA)
  236. GET_PROC_ADDR(s_hWinINET, HttpOpenRequestA)
  237. GET_PROC_ADDR(s_hWinINET, HttpAddRequestHeadersA)
  238. GET_PROC_ADDR(s_hWinINET, HttpSendRequestA)
  239. GET_PROC_ADDR(s_hWinINET, InternetWriteFile)
  240. GET_PROC_ADDR(s_hWinINET, HttpEndRequestA)
  241. GET_PROC_ADDR(s_hWinINET, HttpSendRequestExA)
  242. }
  243. }
  244. LeaveCriticalSection(&g_csDefLoad);
  245. return fRet;
  246. }
  247. // --------------------------------------------------------------------------------
  248. // DemandLoadWSOCK32
  249. // --------------------------------------------------------------------------------
  250. BOOL DemandLoadWSOCK32()
  251. {
  252. BOOL fRet = TRUE;
  253. EnterCriticalSection(&g_csDefLoad);
  254. if (0 == s_hWSOCK)
  255. {
  256. s_hWSOCK = LoadLibrary("WSOCK32.DLL");
  257. AssertSz((BOOL)s_hWSOCK, TEXT("LoadLibrary failed on WSOCK32.DLL"));
  258. if (0 == s_hWSOCK)
  259. fRet = FALSE;
  260. else
  261. {
  262. GET_PROC_ADDR(s_hWSOCK, WSAStartup)
  263. GET_PROC_ADDR(s_hWSOCK, WSACleanup)
  264. GET_PROC_ADDR(s_hWSOCK, WSAGetLastError)
  265. GET_PROC_ADDR(s_hWSOCK, gethostname)
  266. GET_PROC_ADDR(s_hWSOCK, gethostbyname)
  267. GET_PROC_ADDR(s_hWSOCK, WSAAsyncGetHostByName)
  268. GET_PROC_ADDR(s_hWSOCK, inet_addr)
  269. GET_PROC_ADDR(s_hWSOCK, htons)
  270. GET_PROC_ADDR(s_hWSOCK, WSACancelAsyncRequest)
  271. GET_PROC_ADDR(s_hWSOCK, send)
  272. GET_PROC_ADDR(s_hWSOCK, connect)
  273. GET_PROC_ADDR(s_hWSOCK, WSAAsyncSelect)
  274. GET_PROC_ADDR(s_hWSOCK, socket)
  275. GET_PROC_ADDR(s_hWSOCK, inet_ntoa)
  276. GET_PROC_ADDR(s_hWSOCK, closesocket)
  277. GET_PROC_ADDR(s_hWSOCK, recv)
  278. }
  279. }
  280. LeaveCriticalSection(&g_csDefLoad);
  281. return fRet;
  282. }
  283. // --------------------------------------------------------------------------------
  284. // DemandLoadSHELL32
  285. // --------------------------------------------------------------------------------
  286. BOOL DemandLoadSHELL32(void)
  287. {
  288. BOOL fRet = TRUE;
  289. EnterCriticalSection(&g_csDefLoad);
  290. if (0 == s_hShell32)
  291. {
  292. s_hShell32 = LoadLibrary("SHELL32.DLL");
  293. AssertSz((BOOL)s_hShell32, TEXT("LoadLibrary failed on SHELL32.DLL"));
  294. if (0 == s_hShell32)
  295. fRet = FALSE;
  296. else
  297. {
  298. GET_PROC_ADDR(s_hShell32, SHGetPathFromIDListA);
  299. GET_PROC_ADDR(s_hShell32, SHGetSpecialFolderLocation);
  300. GET_PROC_ADDR_ORDINAL(s_hShell32, SHFree, 195);
  301. GET_PROC_ADDR(s_hShell32, SHBrowseForFolderA);
  302. GET_PROC_ADDR(s_hShell32, ShellExecuteA);
  303. GET_PROC_ADDR(s_hShell32, ShellExecuteExA);
  304. GET_PROC_ADDR(s_hShell32, DragQueryFileA);
  305. GET_PROC_ADDR(s_hShell32, SHGetFileInfoA);
  306. GET_PROC_ADDR(s_hShell32, Shell_NotifyIconA);
  307. GET_PROC_ADDR(s_hShell32, ExtractIconA);
  308. GET_PROC_ADDR(s_hShell32, SHFileOperationA);
  309. }
  310. }
  311. LeaveCriticalSection(&g_csDefLoad);
  312. return fRet;
  313. }
  314. #if 0
  315. // --------------------------------------------------------------------------------
  316. // DemandLoadOLEAUT32
  317. // --------------------------------------------------------------------------------
  318. BOOL DemandLoadOLEAUT32(void)
  319. {
  320. BOOL fRet = TRUE;
  321. EnterCriticalSection(&g_csDefLoad);
  322. if (0 == s_hOleAut32)
  323. {
  324. s_hOleAut32 = LoadLibrary("OLEAUT32.DLL");
  325. AssertSz((BOOL)s_hOleAut32, TEXT("LoadLibrary failed on OLEAUT32.DLL"));
  326. if (0 == s_hOleAut32)
  327. fRet = FALSE;
  328. else
  329. {
  330. GET_PROC_ADDR(s_hOleAut32, SafeArrayCreate);
  331. GET_PROC_ADDR(s_hOleAut32, SafeArrayPutElement);
  332. GET_PROC_ADDR(s_hOleAut32, DispInvoke);
  333. GET_PROC_ADDR(s_hOleAut32, DispGetIDsOfNames);
  334. GET_PROC_ADDR(s_hOleAut32, SafeArrayDestroy);
  335. GET_PROC_ADDR(s_hOleAut32, SafeArrayGetUBound);
  336. GET_PROC_ADDR(s_hOleAut32, SafeArrayGetLBound);
  337. GET_PROC_ADDR(s_hOleAut32, SafeArrayGetElement);
  338. GET_PROC_ADDR(s_hOleAut32, SysAllocStringByteLen);
  339. GET_PROC_ADDR(s_hOleAut32, SysReAllocString);
  340. GET_PROC_ADDR(s_hOleAut32, SysAllocStringLen);
  341. GET_PROC_ADDR(s_hOleAut32, SysAllocString);
  342. GET_PROC_ADDR(s_hOleAut32, SysFreeString);
  343. GET_PROC_ADDR(s_hOleAut32, SysStringLen);
  344. GET_PROC_ADDR(s_hOleAut32, VariantInit);
  345. GET_PROC_ADDR(s_hOleAut32, LoadTypeLib);
  346. GET_PROC_ADDR(s_hOleAut32, RegisterTypeLib);
  347. GET_PROC_ADDR(s_hOleAut32, SafeArrayAccessData);
  348. GET_PROC_ADDR(s_hOleAut32, SafeArrayUnaccessData);
  349. GET_PROC_ADDR(s_hOleAut32, SysStringByteLen);
  350. GET_PROC_ADDR(s_hOleAut32, VariantClear);
  351. GET_PROC_ADDR(s_hOleAut32, VariantCopy);
  352. GET_PROC_ADDR(s_hOleAut32, SetErrorInfo);
  353. GET_PROC_ADDR(s_hOleAut32, CreateErrorInfo);
  354. }
  355. }
  356. LeaveCriticalSection(&g_csDefLoad);
  357. return fRet;
  358. }
  359. #endif
  360. // --------------------------------------------------------------------------------
  361. // DemandLoadCOMDLG32
  362. // --------------------------------------------------------------------------------
  363. BOOL DemandLoadCOMDLG32(void)
  364. {
  365. BOOL fRet = TRUE;
  366. EnterCriticalSection(&g_csDefLoad);
  367. if (0 == s_hComDlg32)
  368. {
  369. s_hComDlg32 = LoadLibrary("COMDLG32.DLL");
  370. AssertSz((BOOL)s_hComDlg32, TEXT("LoadLibrary failed on COMDLG32.DLL"));
  371. if (0 == s_hComDlg32)
  372. fRet = FALSE;
  373. else
  374. {
  375. GET_PROC_ADDR(s_hComDlg32, GetSaveFileNameA);
  376. GET_PROC_ADDR(s_hComDlg32, GetOpenFileNameA);
  377. GET_PROC_ADDR(s_hComDlg32, ChooseFontA);
  378. }
  379. }
  380. LeaveCriticalSection(&g_csDefLoad);
  381. return fRet;
  382. }
  383. // --------------------------------------------------------------------------------
  384. // DemandLoadVERSION
  385. // --------------------------------------------------------------------------------
  386. BOOL DemandLoadVERSION(void)
  387. {
  388. BOOL fRet = TRUE;
  389. EnterCriticalSection(&g_csDefLoad);
  390. if (0 == s_hVersion)
  391. {
  392. s_hVersion = LoadLibrary("VERSION.DLL");
  393. AssertSz((BOOL)s_hVersion, TEXT("LoadLibrary failed on VERSION.DLL"));
  394. if (0 == s_hVersion)
  395. fRet = FALSE;
  396. else
  397. {
  398. GET_PROC_ADDR(s_hVersion, VerQueryValueA);
  399. GET_PROC_ADDR(s_hVersion, GetFileVersionInfoA);
  400. GET_PROC_ADDR(s_hVersion, GetFileVersionInfoSizeA);
  401. }
  402. }
  403. LeaveCriticalSection(&g_csDefLoad);
  404. return fRet;
  405. }
  406. // --------------------------------------------------------------------------------
  407. // DemandLoadURLMON
  408. // --------------------------------------------------------------------------------
  409. BOOL DemandLoadURLMON(void)
  410. {
  411. BOOL fRet = TRUE;
  412. EnterCriticalSection(&g_csDefLoad);
  413. if (0 == s_hUrlmon)
  414. {
  415. s_hUrlmon = LoadLibrary("URLMON.DLL");
  416. AssertSz((BOOL)s_hUrlmon, TEXT("LoadLibrary failed on URLMON.DLL"));
  417. if (0 == s_hUrlmon)
  418. fRet = FALSE;
  419. else
  420. {
  421. GET_PROC_ADDR(s_hUrlmon, CreateURLMoniker);
  422. GET_PROC_ADDR(s_hUrlmon, URLOpenBlockingStreamA);
  423. GET_PROC_ADDR(s_hUrlmon, FindMimeFromData);
  424. GET_PROC_ADDR(s_hUrlmon, CoInternetCombineUrl);
  425. GET_PROC_ADDR(s_hUrlmon, RegisterBindStatusCallback);
  426. GET_PROC_ADDR(s_hUrlmon, RevokeBindStatusCallback);
  427. GET_PROC_ADDR(s_hUrlmon, FaultInIEFeature);
  428. GET_PROC_ADDR(s_hUrlmon, CoInternetGetSecurityUrl);
  429. }
  430. }
  431. LeaveCriticalSection(&g_csDefLoad);
  432. return fRet;
  433. }
  434. // --------------------------------------------------------------------------------
  435. // DemandLoadMLANG
  436. // --------------------------------------------------------------------------------
  437. BOOL DemandLoadMLANG(void)
  438. {
  439. BOOL fRet = TRUE;
  440. EnterCriticalSection(&g_csDefLoad);
  441. if (0 == s_hMLANG)
  442. {
  443. #ifndef WIN16
  444. s_hMLANG = LoadLibrary("MLANG.DLL");
  445. #else
  446. s_hMLANG = LoadLibrary("MLANG16.DLL");
  447. #endif // WIN16
  448. AssertSz((BOOL)s_hMLANG, TEXT("LoadLibrary failed on MLANG.DLL"));
  449. if (0 == s_hMLANG)
  450. fRet = FALSE;
  451. else
  452. {
  453. GET_PROC_ADDR(s_hMLANG, IsConvertINetStringAvailable)
  454. GET_PROC_ADDR(s_hMLANG, ConvertINetString)
  455. }
  456. }
  457. LeaveCriticalSection(&g_csDefLoad);
  458. return fRet;
  459. }
  460. // --------------------------------------------------------------------------------
  461. // DemandLoadSHDOCVW
  462. // --------------------------------------------------------------------------------
  463. BOOL DemandLoadSHDOCVW()
  464. {
  465. BOOL fRet = TRUE;
  466. EnterCriticalSection(&g_csDefLoad);
  467. if (0 == s_hShDocVw)
  468. {
  469. s_hShDocVw = LoadLibrary("SHDOCVW.DLL");
  470. AssertSz((BOOL)s_hShDocVw, TEXT("LoadLibrary failed on SHDOCVW.DLL"));
  471. if (0 == s_hShDocVw)
  472. fRet = FALSE;
  473. else
  474. {
  475. GET_PROC_ADDR(s_hShDocVw, AddUrlToFavorites);
  476. GET_PROC_ADDR(s_hShDocVw, SetQueryNetSessionCount);
  477. }
  478. }
  479. LeaveCriticalSection(&g_csDefLoad);
  480. return fRet;
  481. }
  482. // --------------------------------------------------------------------------------
  483. // DemandLoadINETCPL
  484. // --------------------------------------------------------------------------------
  485. BOOL DemandLoadINETCPL()
  486. {
  487. BOOL fRet = TRUE;
  488. EnterCriticalSection(&g_csDefLoad);
  489. if (0 == s_hInetCPL)
  490. {
  491. s_hInetCPL = LoadLibrary("INETCPL.CPL");
  492. AssertSz((BOOL)s_hInetCPL, TEXT("LoadLibrary failed on INETCPL.CPL"));
  493. if (0 == s_hInetCPL)
  494. fRet = FALSE;
  495. else
  496. {
  497. GET_PROC_ADDR(s_hInetCPL, OpenFontsDialog);
  498. GET_PROC_ADDR(s_hInetCPL, LaunchConnectionDialog);
  499. }
  500. }
  501. LeaveCriticalSection(&g_csDefLoad);
  502. return fRet;
  503. }
  504. // --------------------------------------------------------------------------------
  505. // DemandLoadMSO9
  506. // --------------------------------------------------------------------------------
  507. BOOL DemandLoadMSO9(void)
  508. {
  509. BOOL fRet = TRUE;
  510. EnterCriticalSection(&g_csDefLoad);
  511. if (0 == s_hMSO9)
  512. {
  513. #ifdef DEBUG
  514. s_hMSO9 = LoadLibrary("mso9d.DLL");
  515. if (!s_hMSO9)
  516. s_hMSO9 = LoadLibrary("mso9.DLL");
  517. #else
  518. s_hMSO9 = LoadLibrary("mso9.DLL");
  519. #endif
  520. AssertSz((BOOL)s_hMSO9, TEXT("LoadLibrary failed on MSO9.DLL"));
  521. if (0 == s_hMSO9)
  522. fRet = FALSE;
  523. else
  524. {
  525. GET_PROC_ADDR3(s_hMSO9, _MsoFGetComponentManager@4, MsoFGetComponentManager);
  526. }
  527. }
  528. LeaveCriticalSection(&g_csDefLoad);
  529. return fRet;
  530. }
  531. // --------------------------------------------------------------------------------
  532. // DemandLoadWinMM
  533. // --------------------------------------------------------------------------------
  534. BOOL DemandLoadWinMM(void)
  535. {
  536. BOOL fRet = TRUE;
  537. EnterCriticalSection(&g_csDefLoad);
  538. if (0 == s_hWinMM)
  539. {
  540. s_hWinMM = LoadLibrary("winmm.dll");
  541. AssertSz((BOOL)s_hWinMM, TEXT("LoadLibrary failed on WINMM.DLL"));
  542. if (0 == s_hWinMM)
  543. fRet = FALSE;
  544. else
  545. {
  546. GET_PROC_ADDR(s_hWinMM, sndPlaySoundA);
  547. }
  548. }
  549. LeaveCriticalSection(&g_csDefLoad);
  550. return fRet;
  551. }
  552. // --------------------------------------------------------------------------------
  553. // DemandLoadRichEdit
  554. // --------------------------------------------------------------------------------
  555. BOOL DemandLoadRichEdit(void)
  556. {
  557. if (!s_hRichEdit)
  558. {
  559. s_hRichEdit = LoadLibrary("RICHED32.DLL");
  560. if (!s_hRichEdit)
  561. return FALSE;
  562. }
  563. return TRUE;
  564. }
  565. // --------------------------------------------------------------------------------
  566. // DemandLoadPStoreC
  567. // --------------------------------------------------------------------------------
  568. BOOL DemandLoadPStoreC()
  569. {
  570. BOOL fRet = TRUE;
  571. EnterCriticalSection(&g_csDefLoad);
  572. if (0 == s_hPstoreC)
  573. {
  574. s_hPstoreC = LoadLibrary("PSTOREC.DLL");
  575. AssertSz((BOOL)s_hPstoreC, TEXT("LoadLibrary failed on PSTOREC.DLL"));
  576. if (0 == s_hPstoreC)
  577. fRet = FALSE;
  578. else
  579. {
  580. GET_PROC_ADDR(s_hPstoreC, PStoreCreateInstance);
  581. }
  582. }
  583. LeaveCriticalSection(&g_csDefLoad);
  584. return fRet;
  585. }
  586. // --------------------------------------------------------------------------------
  587. // DemandLoadRAS
  588. // --------------------------------------------------------------------------------
  589. BOOL DemandLoadRAS()
  590. {
  591. BOOL fRet = TRUE;
  592. EnterCriticalSection(&g_csDefLoad);
  593. if (0 == s_hRAS)
  594. {
  595. s_hRAS = LoadLibrary("RASAPI32.DLL");
  596. AssertSz((BOOL)s_hRAS, TEXT("LoadLibrary failed on RASAPI32.DLL"));
  597. if (0 == s_hRAS)
  598. fRet = FALSE;
  599. else
  600. {
  601. GET_PROC_ADDR(s_hRAS, RasEnumEntriesA)
  602. GET_PROC_ADDR(s_hRAS, RasEditPhonebookEntryA)
  603. GET_PROC_ADDR(s_hRAS, RasCreatePhonebookEntryA)
  604. }
  605. }
  606. LeaveCriticalSection(&g_csDefLoad);
  607. return fRet;
  608. }
  609. #endif // 0
  610. BOOL IsWin95()
  611. {
  612. OSVERSIONINFOA ver;
  613. ver.dwOSVersionInfoSize = sizeof(ver);
  614. if (GetVersionExA(&ver))
  615. {
  616. return (VER_PLATFORM_WIN32_WINDOWS == ver.dwPlatformId);
  617. }
  618. return FALSE;
  619. }
  620. BOOL MyCryptAcquireContextW(HCRYPTPROV * phProv, LPCWSTR pszContainer,
  621. LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
  622. {
  623. char rgch1[256];
  624. char rgch2[256];
  625. if (pszContainer != NULL)
  626. {
  627. WideCharToMultiByte(CP_ACP, 0, pszContainer, -1, rgch1, sizeof(rgch1),
  628. NULL, NULL);
  629. pszContainer = (LPWSTR) rgch1;
  630. }
  631. if (pszProvider != NULL)
  632. {
  633. WideCharToMultiByte(CP_ACP, 0, pszProvider, -1, rgch2, sizeof(rgch2),
  634. NULL, NULL);
  635. pszProvider = (LPWSTR) rgch2;
  636. }
  637. return CryptAcquireContextA(phProv, (LPCSTR) pszContainer,
  638. (LPCSTR) pszProvider, dwProvType, dwFlags);
  639. }
  640. #if 0
  641. BOOL DemandLoadAdvApi32()
  642. {
  643. BOOL fRet = TRUE;
  644. EnterCriticalSection(&g_csDefLoad);
  645. if (0 == s_hAdvApi)
  646. {
  647. s_hAdvApi = LoadLibrary("ADVAPI32.DLL");
  648. AssertSz((BOOL)s_hAdvApi, TEXT("LoadLibrary failed on ADVAPI32.DLL"));
  649. if (0 == s_hAdvApi)
  650. fRet = FALSE;
  651. else
  652. {
  653. if (IsWin95())
  654. CryptAcquireContextW = MyCryptAcquireContextW;
  655. else
  656. GET_PROC_ADDR(s_hAdvApi, CryptAcquireContextW)
  657. }
  658. }
  659. LeaveCriticalSection(&g_csDefLoad);
  660. return fRet;
  661. }
  662. #endif // 0