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.

231 lines
6.9 KiB

  1. /******************************************************************************
  2. Copyright (C) Microsoft Corporation 1985-1991. All rights reserved.
  3. Title: drvproc.c - Multimedia Systems Media Control Interface
  4. driver for AVI.
  5. *****************************************************************************/
  6. #include "graphic.h"
  7. #include "cnfgdlg.h" // to get IDA_CONFIG
  8. #include "avitask.h" // to get mciaviTaskCleanup()
  9. #ifndef WIN32 // Not used in 32 bit world
  10. void NEAR PASCAL AppExit(HTASK htask, BOOL fNormalExit);
  11. #endif
  12. #define CONFIG_ID 10000L // Use the hiword of dwDriverID to identify
  13. HANDLE ghModule;
  14. extern HWND ghwndConfig;
  15. /* Link to DefDriverProc in MMSystem explicitly, so we don't get the
  16. ** one in USER by mistake.
  17. */
  18. #ifndef WIN32
  19. extern DWORD FAR PASCAL mmDefDriverProc(DWORD, HANDLE, UINT, DWORD, DWORD);
  20. #else
  21. #define mmDefDriverProc DefDriverProc
  22. #endif
  23. #ifndef WIN32
  24. BOOL FAR PASCAL LibMain (HANDLE hModule, int cbHeap, LPSTR lpchCmdLine)
  25. {
  26. ghModule = hModule;
  27. return TRUE;
  28. }
  29. #else
  30. BOOL DllInstanceInit(PVOID hModule, ULONG Reason, PCONTEXT pContext)
  31. {
  32. if (Reason == DLL_PROCESS_ATTACH) {
  33. ghModule = hModule; // All we need to save is our module handle...
  34. } else {
  35. if (Reason == DLL_PROCESS_DETACH) {
  36. }
  37. }
  38. return TRUE;
  39. }
  40. #endif // WIN16
  41. /***************************************************************************
  42. *
  43. * @doc INTERNAL
  44. *
  45. * @api DWORD | DriverProc | The entry point for an installable driver.
  46. *
  47. * @parm DWORD | dwDriverId | For most messages, dwDriverId is the DWORD
  48. * value that the driver returns in response to a DRV_OPEN message.
  49. * Each time that the driver is opened, through the DrvOpen API,
  50. * the driver receives a DRV_OPEN message and can return an
  51. * arbitrary, non-zero, value. The installable driver interface
  52. * saves this value and returns a unique driver handle to the
  53. * application. Whenever the application sends a message to the
  54. * driver using the driver handle, the interface routes the message
  55. * to this entry point and passes the corresponding dwDriverId.
  56. *
  57. * This mechanism allows the driver to use the same or different
  58. * identifiers for multiple opens but ensures that driver handles
  59. * are unique at the application interface layer.
  60. *
  61. * The following messages are not related to a particular open
  62. * instance of the driver. For these messages, the dwDriverId
  63. * will always be ZERO.
  64. *
  65. * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  66. *
  67. * @parm UINT | wMessage | The requested action to be performed. Message
  68. * values below DRV_RESERVED are used for globally defined messages.
  69. * Message values from DRV_RESERVED to DRV_USER are used for
  70. * defined driver portocols. Messages above DRV_USER are used
  71. * for driver specific messages.
  72. *
  73. * @parm DWORD | dwParam1 | Data for this message. Defined separately for
  74. * each message
  75. *
  76. * @parm DWORD | dwParam2 | Data for this message. Defined separately for
  77. * each message
  78. *
  79. * @rdesc Defined separately for each message.
  80. *
  81. ***************************************************************************/
  82. DWORD FAR PASCAL _LOADDS DriverProc (DWORD dwDriverID, HANDLE hDriver, UINT wMessage,
  83. DWORD dwParam1, DWORD dwParam2)
  84. {
  85. DWORD dwRes = 0L;
  86. /*
  87. * critical sections are now per-device. This means they
  88. * cannot be held around the whole driver-proc, since until we open
  89. * the device, we don't have a critical section to hold.
  90. * The critical section is allocated in mciSpecial on opening. It is
  91. * also held in mciDriverEntry, in GraphicWndProc, and around
  92. * all worker thread draw functions.
  93. */
  94. switch (wMessage)
  95. {
  96. // Standard, globally used messages.
  97. case DRV_LOAD:
  98. if (GraphicInit()) // Initialize graphic mgmt.
  99. dwRes = 1L;
  100. else
  101. dwRes = 0L;
  102. break;
  103. case DRV_FREE:
  104. GraphicFree();
  105. dwRes = 1L;
  106. break;
  107. case DRV_OPEN:
  108. if (!dwParam2)
  109. dwRes = CONFIG_ID;
  110. else
  111. dwRes = GraphicDrvOpen((LPMCI_OPEN_DRIVER_PARMS)dwParam2);
  112. break;
  113. case DRV_CLOSE:
  114. /* If we have a configure dialog up, fail the close.
  115. ** Otherwise, we'll be unloaded while we still have the
  116. ** configuration window up.
  117. */
  118. if (ghwndConfig)
  119. dwRes = 0L;
  120. else
  121. dwRes = 1L;
  122. break;
  123. case DRV_ENABLE:
  124. dwRes = 1L;
  125. break;
  126. case DRV_DISABLE:
  127. dwRes = 1L;
  128. break;
  129. case DRV_QUERYCONFIGURE:
  130. dwRes = 1L; /* Yes, we can be configured */
  131. break;
  132. case DRV_CONFIGURE:
  133. ConfigDialog((HWND)(UINT)dwParam1, NULL);
  134. dwRes = 1L;
  135. break;
  136. #ifndef WIN32
  137. //
  138. // sent when a application is terminating
  139. //
  140. // lParam1:
  141. // DRVEA_ABNORMALEXIT
  142. // DRVEA_NORMALEXIT
  143. //
  144. case DRV_EXITAPPLICATION:
  145. AppExit(GetCurrentTask(), (BOOL)dwParam1 == DRVEA_NORMALEXIT);
  146. break;
  147. #endif
  148. default:
  149. if (!HIWORD(dwDriverID) &&
  150. wMessage >= DRV_MCI_FIRST &&
  151. wMessage <= DRV_MCI_LAST)
  152. dwRes = mciDriverEntry ((UINT)dwDriverID,
  153. wMessage,
  154. dwParam1,
  155. (LPMCI_GENERIC_PARMS)dwParam2);
  156. else
  157. dwRes = mmDefDriverProc(dwDriverID,
  158. hDriver,
  159. wMessage,
  160. dwParam1,
  161. dwParam2);
  162. break;
  163. }
  164. return dwRes;
  165. }
  166. #ifndef WIN32
  167. /*****************************************************************************
  168. * @doc INTERNAL
  169. *
  170. * @func void | AppExit |
  171. * a application is exiting
  172. *
  173. ****************************************************************************/
  174. void NEAR PASCAL AppExit(HTASK htask, BOOL fNormalExit)
  175. {
  176. //
  177. // walk the list of open MCIAVI instances and see if
  178. // the dying task is the background task and do cleanup.
  179. //
  180. NPMCIGRAPHIC npMCI;
  181. extern NPMCIGRAPHIC npMCIList; // in graphic.c
  182. for (npMCI=npMCIList; npMCI; npMCI = npMCI->npMCINext) {
  183. if (npMCI->hTask == htask) {
  184. DPF(("Calling mciaviTaskCleanup()\n"));
  185. mciaviTaskCleanup(npMCI);
  186. return;
  187. }
  188. }
  189. }
  190. #endif