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.

213 lines
6.4 KiB

  1. /******************************************************************************
  2. Copyright (C) Microsoft Corporation 1985-1990. All rights reserved.
  3. Title: drvr.c - Installable driver code. Common code
  4. Version: 1.00
  5. Date: 10-Jun-1990
  6. Author: DAVIDDS ROBWI
  7. ------------------------------------------------------------------------------
  8. Change log:
  9. DATE REV DESCRIPTION
  10. ----------- ----- -----------------------------------------------------------
  11. 10-JUN-1990 ROBWI From windows 3.1 installable driver code by davidds
  12. *****************************************************************************/
  13. #include <windows.h>
  14. #include "mmsystem.h"
  15. #include "drvr.h"
  16. int cInstalledDrivers = 0; // Count of installed drivers
  17. HANDLE hInstalledDriverList = 0; // List of installed drivers
  18. typedef LONG (FAR PASCAL *SENDDRIVERMESSAGE31)(HANDLE, WORD, LONG, LONG);
  19. typedef LONG (FAR PASCAL *DEFDRIVERPROC31)(DWORD, HANDLE, WORD, LONG, LONG);
  20. extern SENDDRIVERMESSAGE31 lpSendDriverMessage;
  21. extern DEFDRIVERPROC31 lpDefDriverProc;
  22. extern BOOL fUseWinAPI;
  23. /***************************************************************************
  24. *
  25. * @doc INTERNAL
  26. *
  27. * @api LONG | InternalBroadcastDriverMessage | Send a message to a
  28. * range of drivers.
  29. *
  30. * @parm WORD | hDriverStart | index of first driver to send message to
  31. *
  32. * @parm WORD | message | Message to broadcast.
  33. *
  34. * @parm LONG | lParam1 | First message parameter.
  35. *
  36. * @parm LONG | lParam2 | Second message parameter.
  37. *
  38. * @parm WORD | flags | defines range of drivers as follows:
  39. *
  40. * @flag IBDM_SENDMESSAGE | Only send message to hDriverStart.
  41. *
  42. * @flag IBDM_ONEINSTANCEONLY | This flag is ignored if IBDM_SENDMESSAGE is
  43. * set. Only send message to single instance of each driver.
  44. *
  45. * @flag IBDM_REVERSE | This flag is ignored if IBDM_SENDMESSAGE is set.
  46. * Send message to drivers with indices between
  47. * hDriverStart and 1 instead of hDriverStart and cInstalledDrivers.
  48. * If IBDM_REVERSE is set and hDriverStart is 0 then send messages
  49. * to drivers with indices between cInstalledDrivers and 1.
  50. *
  51. * @rdesc returns non-zero if message was broadcast. If the IBDM_SENDMESSAGE
  52. * flag is set, returns the return result from the driver proc.
  53. *
  54. ***************************************************************************/
  55. LONG FAR PASCAL InternalBroadcastDriverMessage(WORD hDriverStart,
  56. WORD message,
  57. LONG lParam1,
  58. LONG lParam2,
  59. WORD flags)
  60. {
  61. LPDRIVERTABLE lpdt;
  62. LONG result=0;
  63. int id;
  64. int idEnd;
  65. if (!hInstalledDriverList || hDriverStart > cInstalledDrivers)
  66. return(FALSE);
  67. if (flags & IBDM_SENDMESSAGE)
  68. {
  69. if (!hDriverStart)
  70. return (FALSE);
  71. flags &= ~(IBDM_REVERSE | IBDM_ONEINSTANCEONLY);
  72. idEnd = hDriverStart;
  73. }
  74. else
  75. {
  76. if (flags & IBDM_REVERSE)
  77. {
  78. if (!hDriverStart)
  79. hDriverStart = cInstalledDrivers;
  80. idEnd = -1;
  81. }
  82. else
  83. {
  84. if (!hDriverStart)
  85. return (FALSE);
  86. idEnd = cInstalledDrivers;
  87. }
  88. }
  89. hDriverStart--;
  90. lpdt = (LPDRIVERTABLE)GlobalLock(hInstalledDriverList);
  91. for (id = hDriverStart; id != idEnd; ((flags & IBDM_REVERSE) ? id-- : id++))
  92. {
  93. if (lpdt[id].hModule)
  94. {
  95. if ((flags & IBDM_ONEINSTANCEONLY) &&
  96. !lpdt[id].fFirstEntry)
  97. continue;
  98. result =
  99. (*lpdt[id].lpDriverEntryPoint)(lpdt[id].dwDriverIdentifier,
  100. id+1,
  101. message,
  102. lParam1,
  103. lParam2);
  104. }
  105. }
  106. GlobalUnlock(hInstalledDriverList);
  107. return(result);
  108. }
  109. /***************************************************************************
  110. *
  111. * @doc DDK
  112. *
  113. * @api LONG | DrvSendMessage | This function sends a message
  114. * to a specified driver.
  115. *
  116. * @parm HANDLE | hDriver | Specifies the handle of the destination driver.
  117. *
  118. * @parm WORD | wMessage | Specifies a driver message.
  119. *
  120. * @parm LONG | lParam1 | Specifies the first message parameter.
  121. *
  122. * @parm LONG | lParam2 | Specifies the second message parameter.
  123. *
  124. * @rdesc Returns the results returned from the driver.
  125. *
  126. ***************************************************************************/
  127. LONG API DrvSendMessage(HANDLE hDriver, WORD message, LONG lParam1, LONG lParam2)
  128. {
  129. if (fUseWinAPI)
  130. return (*lpSendDriverMessage)(hDriver, message, lParam1,lParam2);
  131. return(InternalBroadcastDriverMessage(hDriver,
  132. message,
  133. lParam1,
  134. lParam2,
  135. IBDM_SENDMESSAGE));
  136. }
  137. /**************************************************************************
  138. *
  139. * @doc DDK
  140. *
  141. * @api LONG | DefDriverProc | This function provides default
  142. * handling of system messages.
  143. *
  144. * @parm DWORD | dwDriverIdentifier | Specifies the identifier of
  145. * the device driver.
  146. *
  147. * @parm HANDLE | hDriver | Specifies the handle of the device driver.
  148. *
  149. * @parm WORD | wMessage | Specifies a driver message.
  150. *
  151. * @parm LONG | lParam1 | Specifies the first message parameter.
  152. *
  153. * @parm LONG | lParam2 | Specifies the second message parameter.
  154. *
  155. * @rdesc Returns 1L for DRV_LOAD, DRV_FREE, DRV_ENABLE, and DRV_DISABLE.
  156. * It returns 0L for all other messages.
  157. *
  158. ***************************************************************************/
  159. LONG API DefDriverProc(DWORD dwDriverIdentifier,
  160. HANDLE hDriver,
  161. WORD message,
  162. LONG lParam1,
  163. LONG lParam2)
  164. {
  165. switch (message)
  166. {
  167. case DRV_LOAD:
  168. case DRV_ENABLE:
  169. case DRV_DISABLE:
  170. case DRV_FREE:
  171. return(1L);
  172. break;
  173. case DRV_INSTALL:
  174. return(DRV_OK);
  175. break;
  176. }
  177. return(0L);
  178. }