Source code of Windows XP (NT5)
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.

112 lines
2.3 KiB

  1. #ifndef __FDI_D_H_INCLUDED__
  2. #define __FDI_D_H_INCLUDED__
  3. #include "fdi.h"
  4. // FDI.DLL delay-load class
  5. class CFdiDll
  6. {
  7. public:
  8. #define DELAY_FDI_HFDI(_fn, _args, _nargs) \
  9. HFDI _fn _args { \
  10. HRESULT hres = Init(); \
  11. HFDI hfdi; \
  12. if (SUCCEEDED(hres)) { \
  13. hfdi = _pfn##_fn _nargs; \
  14. } \
  15. return hfdi; } \
  16. HFDI (FAR DIAMONDAPI* _pfn##_fn) _args;
  17. #define DELAY_FDI_BOOL(_fn, _args, _nargs) \
  18. BOOL _fn _args { \
  19. HRESULT hres = Init(); \
  20. BOOL bRet; \
  21. if (SUCCEEDED(hres)) { \
  22. bRet = _pfn##_fn _nargs; \
  23. } \
  24. return bRet; } \
  25. BOOL (FAR DIAMONDAPI* _pfn##_fn) _args;
  26. HRESULT Init(void);
  27. CFdiDll(BOOL fFreeLibrary = TRUE);
  28. ~CFdiDll();
  29. BOOL m_fInited;
  30. BOOL m_fFreeLibrary;
  31. HMODULE m_hMod;
  32. DELAY_FDI_HFDI(FDICreate,
  33. (PFNALLOC pfnalloc,
  34. PFNFREE pfnfree,
  35. PFNOPEN pfnopen,
  36. PFNREAD pfnread,
  37. PFNWRITE pfnwrite,
  38. PFNCLOSE pfnclose,
  39. PFNSEEK pfnseek,
  40. int cpuType,
  41. PERF perf),
  42. (pfnalloc, pfnfree, pfnopen, pfnread, pfnwrite, pfnclose, pfnseek, cpuType, perf));
  43. DELAY_FDI_BOOL(FDICopy,
  44. (HFDI hfdi,
  45. char *pszCabinet,
  46. char *pszCabPath,
  47. int flags,
  48. PFNFDINOTIFY pfnfdin,
  49. PFNFDIDECRYPT pfnfdid,
  50. void *pvUser),
  51. (hfdi, pszCabinet, pszCabPath, flags, pfnfdin, pfnfdid, pvUser));
  52. DELAY_FDI_BOOL(FDIIsCabinet,
  53. (HFDI hfdi,
  54. int hf,
  55. PFDICABINETINFO pfdici),
  56. (hfdi, hf, pfdici));
  57. DELAY_FDI_BOOL(FDIDestroy,
  58. (HFDI hfdi),
  59. (hfdi));
  60. };
  61. inline CFdiDll::CFdiDll(BOOL fFreeLibrary)
  62. {
  63. m_fInited = FALSE;
  64. m_fFreeLibrary = fFreeLibrary;
  65. }
  66. inline CFdiDll::~CFdiDll()
  67. {
  68. if (m_fInited && m_fFreeLibrary) {
  69. FreeLibrary(m_hMod);
  70. }
  71. }
  72. inline HRESULT CFdiDll::Init(void)
  73. {
  74. if (m_fInited) {
  75. return S_OK;
  76. }
  77. m_hMod = LoadLibrary(TEXT("CABINET.DLL"));
  78. if (!m_hMod) {
  79. return HRESULT_FROM_WIN32(GetLastError());
  80. }
  81. #define CHECKAPI(_fn) \
  82. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(m_hMod, #_fn); \
  83. if (!(_pfn##_fn)) return E_UNEXPECTED;
  84. CHECKAPI(FDICreate);
  85. CHECKAPI(FDICopy);
  86. CHECKAPI(FDIIsCabinet);
  87. CHECKAPI(FDIDestroy);
  88. m_fInited = TRUE;
  89. return S_OK;
  90. }
  91. #endif