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.

168 lines
4.1 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);
  33. static BOOL (FAR DIAMONDAPI *pfnFDIIsCabinet)(
  34. HFDI hfdi,
  35. INT_PTR hf,
  36. PFDICABINETINFO pfdici);
  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);
  45. static BOOL (FAR DIAMONDAPI *pfnFDIDestroy)(
  46. HFDI hfdi);
  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. * FDIIsCabinet -- Determines if file is a cabinet, returns info if it is
  90. *
  91. * See fdi_int.h for entry/exit conditions.
  92. */
  93. BOOL FAR DIAMONDAPI FDIIsCabinet(HFDI hfdi,
  94. INT_PTR hf,
  95. PFDICABINETINFO pfdici)
  96. {
  97. if (pfnFDIIsCabinet == NULL)
  98. {
  99. return(FALSE);
  100. }
  101. return(pfnFDIIsCabinet(hfdi,hf,pfdici));
  102. }
  103. /*
  104. * FDICopy -- extracts files from a cabinet
  105. *
  106. * See fdi_int.h for entry/exit conditions.
  107. */
  108. BOOL FAR DIAMONDAPI FDICopy(HFDI hfdi,
  109. char *pszCabinet,
  110. char *pszCabPath,
  111. int flags,
  112. PFNFDINOTIFY pfnfdin,
  113. PFNFDIDECRYPT pfnfdid,
  114. void *pvUser)
  115. {
  116. if (pfnFDICopy == NULL)
  117. {
  118. return(FALSE);
  119. }
  120. return(pfnFDICopy(hfdi,pszCabinet,pszCabPath,flags,pfnfdin,pfnfdid,pvUser));
  121. }
  122. /*
  123. * FDIDestroy -- Destroy an FDI context
  124. *
  125. * See fdi_int.h for entry/exit conditions.
  126. */
  127. BOOL FAR DIAMONDAPI FDIDestroy(HFDI hfdi)
  128. {
  129. BOOL rc;
  130. if (pfnFDIDestroy == NULL)
  131. {
  132. return(FALSE);
  133. }
  134. rc = pfnFDIDestroy(hfdi);
  135. if (rc == TRUE)
  136. {
  137. FreeLibrary(hCabinetDll);
  138. }
  139. return(rc);
  140. }