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.

272 lines
6.1 KiB

  1. #include "mmcpl.h"
  2. #include "utils.h"
  3. /*
  4. ***************************************************************
  5. * Typedefs
  6. ***************************************************************
  7. */
  8. typedef struct _DYNLOAD_INFO
  9. {
  10. LPCTSTR pszLib;
  11. HMODULE hLib;
  12. short iRefCnt;
  13. }
  14. DYNLOAD_INFO, *PDYNLOAD_INFO;
  15. /*
  16. ***************************************************************
  17. * File Globals
  18. ***************************************************************
  19. */
  20. static SZCODE aszMSACM32[] = TEXT("MSACM32.DLL");
  21. static SZCODE aszAVIFIL32[] = TEXT("AVIFIL32.DLL");
  22. static SZCODE aszMSVFW32[] = TEXT("MSVFW32.DLL");
  23. static SZCODE aszVERSION[] = TEXT("VERSION.DLL");
  24. DYNLOAD_INFO DynLoadInfo[] =
  25. {
  26. aszMSACM32, 0, 0,
  27. aszAVIFIL32, 0, 0,
  28. aszMSVFW32, 0, 0,
  29. aszVERSION, 0, 0,
  30. NULL, 0, 0
  31. };
  32. static const char cszTacmFormatDetailsW[] = "acmFormatDetailsW";
  33. static const char cszTacmFormatTagDetailsW[] = "acmFormatTagDetailsW";
  34. static const char cszTacmDriverDetailsW[] = "acmDriverDetailsW";
  35. static const char cszTacmDriverMessage[] = "acmDriverMessage";
  36. static const char cszTacmDriverAddW[] = "acmDriverAddW";
  37. static const char cszTacmDriverEnum[] = "acmDriverEnum";
  38. static const char cszTacmDriverPriority[] = "acmDriverPriority";
  39. static const char cszTacmDriverRemove[] = "acmDriverRemove";
  40. static const char cszTacmMetrics[] = "acmMetrics";
  41. static const char cszTacmFormatChooseW[] = "acmFormatChooseW";
  42. PROC_INFO ACMProcs[] =
  43. {
  44. cszTacmFormatDetailsW, 0,
  45. cszTacmFormatTagDetailsW, 0,
  46. cszTacmDriverDetailsW, 0,
  47. cszTacmDriverMessage, 0,
  48. cszTacmDriverAddW, 0,
  49. cszTacmDriverEnum, 0,
  50. cszTacmDriverPriority, 0,
  51. cszTacmDriverRemove, 0,
  52. cszTacmMetrics, 0,
  53. cszTacmFormatChooseW, 0,
  54. NULL, 0
  55. };
  56. static const char cszICClose[] = "ICClose";
  57. static const char cszICGetInfo[] = "ICGetInfo";
  58. static const char cszICLocate[] = "ICLocate";
  59. static const char cszMCIWndCreateW[] = "MCIWndCreateW";
  60. PROC_INFO VFWProcs[] =
  61. {
  62. cszICClose, 0,
  63. cszICGetInfo, 0,
  64. cszICLocate, 0,
  65. cszMCIWndCreateW, 0,
  66. NULL, 0
  67. };
  68. static const char cszAVIFileRelease[] = "AVIFileRelease";
  69. static const char cszAVIStreamRelease[] = "AVIStreamRelease";
  70. static const char cszAVIStreamSampleToTime[] = "AVIStreamSampleToTime";
  71. static const char cszAVIStreamStart[] = "AVIStreamStart";
  72. static const char cszAVIStreamLength[] = "AVIStreamLength";
  73. static const char cszAVIStreamReadFormat[] = "AVIStreamReadFormat";
  74. static const char cszAVIStreamInfoW[] = "AVIStreamInfoW";
  75. static const char cszAVIFileGetStream[] = "AVIFileGetStream";
  76. static const char cszAVIFileOpenW[] = "AVIFileOpenW";
  77. static const char cszAVIFileInit[] = "AVIFileInit";
  78. static const char cszAVIFileExit[] = "AVIFileExit";
  79. PROC_INFO AVIProcs[] =
  80. {
  81. cszAVIFileRelease, 0,
  82. cszAVIStreamRelease, 0,
  83. cszAVIStreamSampleToTime, 0,
  84. cszAVIStreamStart, 0,
  85. cszAVIStreamLength, 0,
  86. cszAVIStreamReadFormat, 0,
  87. cszAVIStreamInfoW, 0,
  88. cszAVIFileGetStream, 0,
  89. cszAVIFileOpenW, 0,
  90. cszAVIFileInit, 0,
  91. cszAVIFileExit, 0,
  92. NULL, 0
  93. };
  94. static const char cszVerQueryValueW[] = "VerQueryValueW";
  95. static const char cszGetFileVersionInfoW[] = "GetFileVersionInfoW";
  96. static const char cszGetFileVersionInfoSizeW[] = "GetFileVersionInfoSizeW";
  97. PROC_INFO VERSIONProcs[] =
  98. {
  99. cszVerQueryValueW, 0,
  100. cszGetFileVersionInfoW, 0,
  101. cszGetFileVersionInfoSizeW, 0,
  102. NULL, 0
  103. };
  104. /*
  105. ***************************************************************
  106. ***************************************************************
  107. */
  108. STATIC BOOL LoadLibraryAndProcs(LPCTSTR pLibrary, PPROC_INFO pProcInfo)
  109. {
  110. HMODULE hLibrary;
  111. PPROC_INFO p;
  112. PDYNLOAD_INFO pLib;
  113. BOOL fPrevLoaded = FALSE;
  114. #ifdef DEBUG_BUILT_LINKED
  115. return TRUE;
  116. #endif
  117. if (pProcInfo->Address) //Already loaded
  118. {
  119. fPrevLoaded = TRUE;
  120. goto UpdateDynLoadInfo;
  121. }
  122. hLibrary = LoadLibrary(pLibrary);
  123. if (hLibrary == NULL)
  124. {
  125. DPF("LoadLibrary failed for %s \r\n", pLibrary);
  126. return FALSE;
  127. }
  128. p = pProcInfo;
  129. while (p->Name)
  130. {
  131. p->Address = GetProcAddress(hLibrary, p->Name);
  132. if (p->Address == NULL)
  133. {
  134. DPF("GetProcAddress failed for %s \r\n", p->Name);
  135. FreeLibrary(hLibrary);
  136. return FALSE;
  137. }
  138. p++;
  139. }
  140. UpdateDynLoadInfo:
  141. pLib = DynLoadInfo;
  142. while (pLib->pszLib)
  143. {
  144. if (!lstrcmpi(pLib->pszLib, pLibrary))
  145. {
  146. pLib->iRefCnt++;
  147. if (!fPrevLoaded)
  148. {
  149. pLib->hLib = hLibrary;
  150. }
  151. break;
  152. }
  153. pLib++;
  154. }
  155. return TRUE;
  156. }
  157. STATIC BOOL FreeLibraryAndProcs(LPCTSTR pLibrary, PPROC_INFO pProcInfo)
  158. {
  159. PDYNLOAD_INFO p;
  160. #ifdef DEBUG_BUILT_LINKED
  161. return TRUE;
  162. #endif
  163. p = DynLoadInfo;
  164. while (p->pszLib)
  165. {
  166. if (!lstrcmpi(p->pszLib, pLibrary))
  167. {
  168. PPROC_INFO ppi;
  169. p->iRefCnt--;
  170. if (p->iRefCnt > 0)
  171. return TRUE;
  172. if (!p->hLib)
  173. return FALSE;
  174. DPF("Freeing Library %s \r\n",p->pszLib);
  175. FreeLibrary(p->hLib);
  176. p->hLib = 0;
  177. ppi = pProcInfo;
  178. while (ppi->Name)
  179. {
  180. ppi->Address = 0;
  181. ppi++;
  182. }
  183. return TRUE;
  184. }
  185. p++;
  186. }
  187. return FALSE;
  188. }
  189. BOOL LoadACM()
  190. {
  191. DPF("***LOADING ACM***\r\n");
  192. return LoadLibraryAndProcs(aszMSACM32, ACMProcs);
  193. }
  194. BOOL FreeACM()
  195. {
  196. DPF("***FREEING ACM***\r\n");
  197. return FreeLibraryAndProcs(aszMSACM32, ACMProcs);
  198. }
  199. BOOL LoadAVI()
  200. {
  201. DPF("***LOADING AVI***\r\n");
  202. return LoadLibraryAndProcs(aszAVIFIL32, AVIProcs);
  203. }
  204. BOOL FreeAVI()
  205. {
  206. DPF("***FREEING AVI***\r\n");
  207. return FreeLibraryAndProcs(aszAVIFIL32, AVIProcs);
  208. }
  209. BOOL LoadVFW()
  210. {
  211. DPF("***LOADING VFW***\r\n");
  212. return LoadLibraryAndProcs(aszMSVFW32, VFWProcs);
  213. }
  214. BOOL FreeVFW()
  215. {
  216. DPF("***FREEING VFW***\r\n");
  217. return FreeLibraryAndProcs(aszMSVFW32, VFWProcs);
  218. }
  219. BOOL LoadVERSION()
  220. {
  221. DPF("***LOADING VERSION***\r\n");
  222. return LoadLibraryAndProcs(aszVERSION, VERSIONProcs);
  223. }
  224. BOOL FreeVERSION()
  225. {
  226. DPF("***FREEING VERSION***\r\n");
  227. return FreeLibraryAndProcs(aszVERSION, VERSIONProcs);
  228. }