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.

173 lines
9.1 KiB

  1. #include "_apipch.h"
  2. #include <pstore.h>
  3. #define _CRYPTDLG_
  4. #include <cryptdlg.h>
  5. #pragma hdrstop
  6. #pragma warning(disable:4229) // No warnings when modifiers used on data
  7. // flags to enable selective def-loading of dlls.
  8. #define DEFLOAD_PSTOREC
  9. #define DEFLOAD_CRYPTDLG
  10. #define ENSURE_LOADED(_hinst, _dll) (_hinst ? TRUE : (BOOL)(_hinst = LoadLibrary(TEXT(#_dll))))
  11. #define DELAY_LOAD_ERR(_hinst, _dll, _ret, _fn, _args, _nargs, _err) \
  12. _ret __stdcall _fn _args \
  13. { \
  14. static _ret (* __stdcall _pfn##_fn) _args = NULL; \
  15. if (!ENSURE_LOADED(_hinst, _dll)) \
  16. { \
  17. if(!_hinst) DebugTrace(TEXT("LoadLibrary failed on ") ## TEXT(#_dll)); \
  18. return (_ret)_err; \
  19. } \
  20. if (_pfn##_fn == NULL) \
  21. { \
  22. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(_hinst, #_fn); \
  23. if(!_pfn##_fn) DebugTrace(TEXT("GetProcAddress failed on ") ## TEXT(#_fn)); \
  24. if (_pfn##_fn == NULL) \
  25. return (_ret)_err; \
  26. } \
  27. return _pfn##_fn _nargs; \
  28. }
  29. #define DELAY_LOAD(_hinst, _dll, _ret, _fn, _args, _nargs) DELAY_LOAD_ERR(_hinst, _dll, _ret, _fn, _args, _nargs, 0)
  30. #define DELAY_LOAD_HRESULT(_hinst, _dll, _fn, _args, _nargs) DELAY_LOAD_ERR(_hinst, _dll, HRESULT, _fn, _args, _nargs, E_FAIL)
  31. #define DELAY_LOAD_SAFEARRAY(_hinst, _dll, _fn, _args, _nargs) DELAY_LOAD_ERR(_hinst, _dll, SAFEARRAY *, _fn, _args, _nargs, NULL)
  32. #define DELAY_LOAD_UINT(_hinst, _dll, _fn, _args, _nargs) DELAY_LOAD_ERR(_hinst, _dll, UINT, _fn, _args, _nargs, 0)
  33. #define DELAY_LOAD_BOOL(_hinst, _dll, _fn, _args, _nargs) DELAY_LOAD_ERR(_hinst, _dll, BOOL, _fn, _args, _nargs, FALSE)
  34. #define DELAY_LOAD_VOID(_hinst, _dll, _fn, _args, _nargs) \
  35. void __stdcall _fn _args \
  36. { \
  37. static void (* __stdcall _pfn##_fn) _args = NULL; \
  38. if (!ENSURE_LOADED(_hinst, _dll)) \
  39. { \
  40. if(!_hinst) DebugTrace(TEXT("LoadLibrary failed on ") ## TEXT(#_dll)); \
  41. return; \
  42. } \
  43. if (_pfn##_fn == NULL) \
  44. { \
  45. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(_hinst, #_fn); \
  46. if(!_pfn##_fn) DebugTrace(TEXT("GetProcAddress failed on ") ## TEXT(#_fn)); \
  47. if (_pfn##_fn == NULL) \
  48. return; \
  49. } \
  50. _pfn##_fn _nargs; \
  51. }
  52. // For private entrypoints exported by ordinal.
  53. #define DELAY_LOAD_ORD_ERR(_hinst, _dll, _ret, _fn, _ord, _args, _nargs, _err) \
  54. _ret __stdcall _fn _args \
  55. { \
  56. static _ret (* __stdcall _pfn##_fn) _args = NULL; \
  57. if (!ENSURE_LOADED(_hinst, _dll)) \
  58. { \
  59. if(!_hinst) DebugTrace(TEXT("LoadLibrary failed on ") ## TEXT(#_dll)); \
  60. return (_ret)_err; \
  61. } \
  62. if (_pfn##_fn == NULL) \
  63. { \
  64. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(_hinst, (LPSTR) _ord); \
  65. if(!_pfn##_fn) DebugTrace(TEXT("GetProcAddress failed on ") ## TEXT(#_fn)); \
  66. if (_pfn##_fn == NULL) \
  67. return (_ret)_err; \
  68. } \
  69. return _pfn##_fn _nargs; \
  70. }
  71. #define DELAY_LOAD_ORD(_hinst, _dll, _ret, _fn, _ord, _args, _nargs) DELAY_LOAD_ORD_ERR(_hinst, _dll, _ret, _fn, _ord, _args, _nargs, 0)
  72. #define DELAY_LOAD_VOID_ORD(_hinst, _dll, _fn, _ord, _args, _nargs) \
  73. void __stdcall _fn _args \
  74. { \
  75. static void (* __stdcall _pfn##_fn) _args = NULL; \
  76. if (!ENSURE_LOADED(_hinst, _dll)) \
  77. { \
  78. if(!_hinst) DebugTrace(TEXT("LoadLibrary failed on ") ## TEXT(#_dll)); \
  79. return; \
  80. } \
  81. if (_pfn##_fn == NULL) \
  82. { \
  83. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(_hinst, MAKEINTRESOURCE(_ord)); \
  84. if(!_pfn##_fn) DebugTrace(TEXT("GetProcAddress failed on ") ## TEXT(#_fn)); \
  85. if (_pfn##_fn == NULL) \
  86. return; \
  87. } \
  88. _pfn##_fn _nargs; \
  89. }
  90. #ifdef DEFLOAD_PSTOREC
  91. // ------- pstorec.dll -------
  92. HINSTANCE g_hinstPSTOREC = NULL;
  93. #ifndef WIN16
  94. DELAY_LOAD(g_hinstPSTOREC, PSTOREC.DLL, HRESULT, PStoreCreateInstance,
  95. (IPStore __RPC_FAR *__RPC_FAR *ppProvider, PST_PROVIDERID __RPC_FAR *pProviderID, void __RPC_FAR *pReserved, DWORD dwFlags),
  96. (ppProvider, pProviderID, pReserved, dwFlags));
  97. DELAY_LOAD(g_hinstPSTOREC, PSTOREC.DLL, HRESULT, PStoreEnumProviders,
  98. (DWORD dwFlags, IEnumPStoreProviders __RPC_FAR *__RPC_FAR *ppenum),
  99. (dwFlags, ppenum));
  100. #endif
  101. #endif
  102. #ifdef DEFLOAD_CRYPTDLG
  103. // ------- cryptdlg.dll -------
  104. HINSTANCE g_hinstCRYPTDLG = NULL;
  105. #ifndef WIN16
  106. DELAY_LOAD(g_hinstCRYPTDLG, CRYPTDLG.DLL, BOOL, CertViewPropertiesA,
  107. (PCERT_VIEWPROPERTIES_STRUCT_A pCertViewInfo),
  108. (pCertViewInfo));
  109. DELAY_LOAD(g_hinstCRYPTDLG, CRYPTDLG.DLL, BOOL, CertViewPropertiesCryptUIA,
  110. (PCERT_VIEWPROPERTIESCRYPTUI_STRUCT_A pCertViewInfo),
  111. (pCertViewInfo));
  112. #endif
  113. #endif
  114. void DefLoadFreeLibraries()
  115. {
  116. #ifdef DEFLOAD_PSTOREC
  117. if (g_hinstPSTOREC)
  118. {
  119. FreeLibrary(g_hinstPSTOREC);
  120. g_hinstPSTOREC=0;
  121. }
  122. if (g_hinstCRYPTDLG)
  123. {
  124. FreeLibrary(g_hinstCRYPTDLG);
  125. g_hinstCRYPTDLG=0;
  126. }
  127. #endif
  128. }
  129. // --------------------------------------------
  130. // these macros produce code that looks like
  131. //
  132. #if 0
  133. BOOL GetOpenFileName(LPOPENFILENAME pof)
  134. {
  135. static BOOL (*pfnGetOpenFileName)(LPOPENFILENAME pof);
  136. if (ENSURE_LOADED(g_hinstCOMDLG32, "COMDLG32.DLL"))
  137. {
  138. if (pfnGetOpenFileName == NULL)
  139. pfnGetOpenFileName = (BOOL (*)(LPOPENFILENAME))GetProcAddress(g_hinstCOMDLG32, "GetOpenFileNameW");
  140. if (pfnGetOpenFileName)
  141. return pfnGetOpenFileName(pof);
  142. }
  143. return -1;
  144. }
  145. #endif
  146. #pragma warning(default:4229)