Windows NT 4.0 source code leak
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.

263 lines
7.8 KiB

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