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.

293 lines
9.3 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * drvproc.c
  4. *
  5. * Copyright (c) 1991-1992 Microsoft Corporation. All Rights Reserved.
  6. *
  7. ***************************************************************************/
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #include "registry.h"
  11. #include "mpu401.h"
  12. /* Temp definition until DefDriverProc gets properly defined */
  13. /***************************************************************************
  14. * @doc INTERNAL
  15. *
  16. * @api LRESULT | DriverProc | The entry point for an installable driver.
  17. *
  18. * @parm DWORD | dwDriverId | For most messages, <p dwDriverId> is the DWORD
  19. * value that the driver returns in response to a <m DRV_OPEN> message.
  20. * Each time that the driver is opened, through the <f DrvOpen> API,
  21. * the driver receives a <m DRV_OPEN> message and can return an
  22. * arbitrary, non-zero value. The installable driver interface
  23. * saves this value and returns a unique driver handle to the
  24. * application. Whenever the application sends a message to the
  25. * driver using the driver handle, the interface routes the message
  26. * to this entry point and passes the corresponding <p dwDriverId>.
  27. * This mechanism allows the driver to use the same or different
  28. * identifiers for multiple opens but ensures that driver handles
  29. * are unique at the application interface layer.
  30. *
  31. * The following messages are not related to a particular open
  32. * instance of the driver. For these messages, the dwDriverId
  33. * will always be zero.
  34. *
  35. * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  36. *
  37. * @parm HDRVR | hDriver | This is the handle returned to the
  38. * application by the driver interface.
  39. *
  40. * @parm UINT | uiMessage | The requested action to be performed. Message
  41. * values below <m DRV_RESERVED> are used for globally defined messages.
  42. * Message values from <m DRV_RESERVED> to <m DRV_USER> are used for
  43. * defined driver protocols. Messages above <m DRV_USER> are used
  44. * for driver specific messages.
  45. *
  46. * @parm LPARAM | lParam1 | Data for this message. Defined separately for
  47. * each message
  48. *
  49. * @parm LPARAM | lParam2 | Data for this message. Defined separately for
  50. * each message
  51. *
  52. * @rdesc Defined separately for each message.
  53. ***************************************************************************/
  54. LRESULT DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  55. {
  56. LRESULT lr;
  57. switch (uiMessage) {
  58. case DRV_LOAD:
  59. D1("DRV_LOAD");
  60. /*
  61. Sent to the driver when it is loaded. Always the first
  62. message received by a driver.
  63. dwDriverID is 0L.
  64. lParam1 is 0L.
  65. lParam2 is 0L.
  66. Return 0L to fail the load.
  67. DefDriverProc will return NON-ZERO so we don't have to
  68. handle DRV_LOAD
  69. */
  70. ghModule = GetDriverModuleHandle(hDriver);
  71. return (LRESULT)1L;
  72. case DRV_FREE:
  73. D1("DRV_FREE");
  74. /*
  75. Sent to the driver when it is about to be discarded. This
  76. will always be the last message received by a driver before
  77. it is freed.
  78. dwDriverID is 0L.
  79. lParam1 is 0L.
  80. lParam2 is 0L.
  81. Return value is ignored.
  82. */
  83. return (LRESULT)1L;
  84. case DRV_OPEN:
  85. D1("DRV_OPEN");
  86. /*
  87. Sent to the driver when it is opened.
  88. dwDriverID is 0L.
  89. lParam1 is a far pointer to a zero-terminated string
  90. containing the name used to open the driver.
  91. lParam2 is passed through from the drvOpen call.
  92. Return 0L to fail the open.
  93. DefDriverProc will return ZERO so we do have to
  94. handle the DRV_OPEN message.
  95. */
  96. //
  97. // See if we can get access to our registry node
  98. //
  99. return (LRESULT)1L;
  100. case DRV_CLOSE:
  101. D1("DRV_CLOSE");
  102. /*
  103. Sent to the driver when it is closed. Drivers are unloaded
  104. when the close count reaches zero.
  105. dwDriverID is the driver identifier returned from the
  106. corresponding DRV_OPEN.
  107. lParam1 is passed through from the drvClose call.
  108. lParam2 is passed through from the drvClose call.
  109. Return 0L to fail the close.
  110. DefDriverProc will return ZERO so we do have to
  111. handle the DRV_CLOSE message.
  112. */
  113. return (LRESULT)1L;
  114. case DRV_ENABLE:
  115. D1("DRV_ENABLE");
  116. /*
  117. Sent to the driver when the driver is loaded or reloaded
  118. and whenever Windows is enabled. Drivers should only
  119. hook interrupts or expect ANY part of the driver to be in
  120. memory between enable and disable messages
  121. dwDriverID is 0L.
  122. lParam1 is 0L.
  123. lParam2 is 0L.
  124. Return value is ignored.
  125. */
  126. //return (LRESULT)(Enable() ? 1L : 0L);
  127. return 1L;
  128. case DRV_DISABLE:
  129. D1("DRV_DISABLE");
  130. /*
  131. Sent to the driver before the driver is freed.
  132. and whenever Windows is disabled
  133. dwDriverID is 0L.
  134. lParam1 is 0L.
  135. lParam2 is 0L.
  136. Return value is ignored.
  137. */
  138. // Disable();
  139. return (LRESULT)1L;
  140. case DRV_QUERYCONFIGURE:
  141. D1("DRV_QUERYCONFIGURE");
  142. /*
  143. Sent to the driver so that applications can
  144. determine whether the driver supports custom
  145. configuration. The driver should return a
  146. non-zero value to indicate that configuration
  147. is supported.
  148. dwDriverID is the value returned from the DRV_OPEN
  149. call that must have succeeded before this message
  150. was sent.
  151. lParam1 is passed from the app and is undefined.
  152. lParam2 is passed from the app and is undefined.
  153. Return 0L to indicate configuration NOT supported.
  154. */
  155. //
  156. // Check to see if we can access the registry.
  157. // Note thta this may be a config immediately after install
  158. // so we may not have a service or node yet
  159. //
  160. DrvCreateServicesNode(STR_DRIVERNAME,
  161. SoundDriverTypeNormal,
  162. &RegAccess,
  163. FALSE); // Don't create
  164. lr = (LRESULT)DrvAccess(&RegAccess);
  165. DrvCloseServiceManager(&RegAccess);
  166. return lr;
  167. case DRV_CONFIGURE:
  168. D1("DRV_CONFIGURE");
  169. /*
  170. Sent to the driver so that it can display a custom
  171. configuration dialog box.
  172. lParam1 is passed from the app. and should contain
  173. the parent window handle in the loword.
  174. lParam2 is passed from the app and is undefined.
  175. Return value is undefined.
  176. Drivers should create their own section in system.ini.
  177. The section name should be the driver name.
  178. */
  179. DrvCreateServicesNode(STR_DRIVERNAME,
  180. SoundDriverTypeNormal,
  181. &RegAccess,
  182. FALSE); // Don't create
  183. lr = (LRESULT)Config((HWND)lParam1, ghModule);
  184. DrvCloseServiceManager(&RegAccess);
  185. return lr;
  186. case DRV_INSTALL:
  187. /*
  188. * See if we can support install
  189. */
  190. DrvCreateServicesNode(STR_DRIVERNAME,
  191. SoundDriverTypeNormal,
  192. &RegAccess,
  193. FALSE); // Don't create
  194. if (!DrvAccess(&RegAccess)) {
  195. ConfigErrorMsgBox((HWND)lParam1, IDS_INSUFFICIENT_PRIVILEGE);
  196. return (LRESULT)DRVCNF_CANCEL;
  197. }
  198. DrvCloseServiceManager(&RegAccess);
  199. /*
  200. * Set a flag so that config knows we're installing something
  201. */
  202. bInstall = TRUE;
  203. D1("DRV_INSTALL");
  204. return (LRESULT)DRVCNF_RESTART;
  205. case DRV_REMOVE:
  206. /*
  207. * See if we can support removal
  208. */
  209. DrvCreateServicesNode(STR_DRIVERNAME,
  210. SoundDriverTypeNormal,
  211. &RegAccess,
  212. FALSE); // Don't create
  213. if (!DrvAccess(&RegAccess)) {
  214. ConfigErrorMsgBox((HWND)lParam1, IDS_INSUFFICIENT_PRIVILEGE);
  215. return (LRESULT)DRVCNF_CANCEL;
  216. }
  217. lr = ConfigRemove((HWND)lParam1);
  218. DrvCloseServiceManager(&RegAccess);
  219. D1("DRV_REMOVE");
  220. return lr;
  221. default:
  222. return DefDriverProc(dwDriverID, hDriver,uiMessage,lParam1,lParam2);
  223. }
  224. }