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.

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