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.

149 lines
3.9 KiB

  1. /*
  2. * FDIDLL.C -- FDI interface using CABINET.DLL
  3. *
  4. * Microsoft Confidential
  5. * Copyright (C) Microsoft Corporation 1997
  6. * All Rights Reserved.
  7. *
  8. * Author:
  9. * Mike Sliger
  10. *
  11. * History:
  12. * 21-Jan-1997 msliger Initial version
  13. * 24-Jan-1997 msliger Changed to public include file
  14. *
  15. * Overview:
  16. * This code is a wrapper which provides access to the actual FDI code
  17. * in CABINET.DLL. CABINET.DLL dynamically loads/unloads as needed.
  18. */
  19. #include <windows.h>
  20. #include "fdi.h"
  21. static HINSTANCE hCabinetDll; /* DLL module handle */
  22. /* pointers to the functions in the DLL */
  23. static HFDI (FAR DIAMONDAPI *pfnFDICreate)(
  24. PFNALLOC pfnalloc,
  25. PFNFREE pfnfree,
  26. PFNOPEN pfnopen,
  27. PFNREAD pfnread,
  28. PFNWRITE pfnwrite,
  29. PFNCLOSE pfnclose,
  30. PFNSEEK pfnseek,
  31. int cpuType,
  32. PERF perf) = NULL;
  33. static BOOL (FAR DIAMONDAPI *pfnFDIIsCabinet)(
  34. HFDI hfdi,
  35. INT_PTR hf,
  36. PFDICABINETINFO pfdici) = NULL;
  37. static BOOL (FAR DIAMONDAPI *pfnFDICopy)(
  38. HFDI hfdi,
  39. char *pszCabinet,
  40. char *pszCabPath,
  41. int flags,
  42. PFNFDINOTIFY pfnfdin,
  43. PFNFDIDECRYPT pfnfdid,
  44. void *pvUser) = NULL;
  45. static BOOL (FAR DIAMONDAPI *pfnFDIDestroy)(
  46. HFDI hfdi) = NULL;
  47. /*
  48. * FDICreate -- Create an FDI context
  49. *
  50. * See fdi_int.h for entry/exit conditions.
  51. */
  52. HFDI FAR DIAMONDAPI FDICreate(PFNALLOC pfnalloc,
  53. PFNFREE pfnfree,
  54. PFNOPEN pfnopen,
  55. PFNREAD pfnread,
  56. PFNWRITE pfnwrite,
  57. PFNCLOSE pfnclose,
  58. PFNSEEK pfnseek,
  59. int cpuType,
  60. PERF perf)
  61. {
  62. HFDI hfdi;
  63. hCabinetDll = LoadLibrary(TEXT("CABINET"));
  64. if (hCabinetDll == NULL)
  65. {
  66. return(NULL);
  67. }
  68. pfnFDICreate = (void *) GetProcAddress(hCabinetDll,"FDICreate");
  69. pfnFDICopy = (void *) GetProcAddress(hCabinetDll,"FDICopy");
  70. pfnFDIIsCabinet = (void *) GetProcAddress(hCabinetDll,"FDIIsCabinet");
  71. pfnFDIDestroy = (void *) GetProcAddress(hCabinetDll,"FDIDestroy");
  72. if ((pfnFDICreate == NULL) ||
  73. (pfnFDICopy == NULL) ||
  74. (pfnFDIIsCabinet == NULL) ||
  75. (pfnFDIDestroy == NULL))
  76. {
  77. FreeLibrary(hCabinetDll);
  78. return(NULL);
  79. }
  80. hfdi = pfnFDICreate(pfnalloc,pfnfree,
  81. pfnopen,pfnread,pfnwrite,pfnclose,pfnseek,cpuType,perf);
  82. if (hfdi == NULL)
  83. {
  84. FreeLibrary(hCabinetDll);
  85. }
  86. return(hfdi);
  87. }
  88. /*
  89. * FDICopy -- extracts files from a cabinet
  90. *
  91. * See fdi_int.h for entry/exit conditions.
  92. */
  93. BOOL FAR DIAMONDAPI FDICopy(HFDI hfdi,
  94. char *pszCabinet,
  95. char *pszCabPath,
  96. int flags,
  97. PFNFDINOTIFY pfnfdin,
  98. PFNFDIDECRYPT pfnfdid,
  99. void *pvUser)
  100. {
  101. if (pfnFDICopy == NULL)
  102. {
  103. return(FALSE);
  104. }
  105. return(pfnFDICopy(hfdi,pszCabinet,pszCabPath,flags,pfnfdin,pfnfdid,pvUser));
  106. }
  107. /*
  108. * FDIDestroy -- Destroy an FDI context
  109. *
  110. * See fdi_int.h for entry/exit conditions.
  111. */
  112. BOOL FAR DIAMONDAPI FDIDestroy(HFDI hfdi)
  113. {
  114. BOOL rc;
  115. if (pfnFDIDestroy == NULL)
  116. {
  117. return(FALSE);
  118. }
  119. rc = pfnFDIDestroy(hfdi);
  120. if (rc == TRUE)
  121. {
  122. FreeLibrary(hCabinetDll);
  123. }
  124. return(rc);
  125. }