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.

266 lines
6.6 KiB

  1. /* Installable drivers for windows. Often used stuff.
  2. */
  3. #include "user.h"
  4. LRESULT FAR InternalBroadcastDriverMessage(HDRVR hDriverStart,
  5. WORD message,
  6. LPARAM lParam1,
  7. LPARAM lParam2,
  8. LONG flags)
  9. /* effects: Allows for sending messages to the drivers. Supports sending
  10. * messages to one instance of every driver, supports running through the list
  11. * in reverse order, and supports sending a message to a particular driver id.
  12. *
  13. * If flags & IBDM_SENDMESSAGE then only send message to
  14. * hDriverStart and ignore other flags. Fail if not
  15. * 0<hDriverStart<=cInstalledDrivers.
  16. *
  17. * If flags & IBDM_FIRSTINSTANCEONLY then send message to one instance of
  18. * each driver between hDriverStart and cInstalledDrivers.
  19. *
  20. * If flags & IBDM_REVERSE then send message to drivers in reverse
  21. * order from hDriverStart to 1. If hDriverStart is 0 then send
  22. * messages to drivers from cInstalledDrivers to 1
  23. */
  24. {
  25. LPDRIVERTABLE lpdt;
  26. LRESULT result=0;
  27. int id;
  28. int idEnd;
  29. if (!hInstalledDriverList || (int)hDriverStart > cInstalledDrivers)
  30. return(FALSE);
  31. if (idFirstDriver == -1)
  32. /* No drivers in the list
  33. */
  34. return(FALSE);
  35. lpdt = (LPDRIVERTABLE)MAKELP(hInstalledDriverList,0);
  36. if (flags & IBDM_SENDMESSAGE)
  37. {
  38. if (!hDriverStart)
  39. return(FALSE);
  40. idEnd = lpdt[(int)hDriverStart-1].idNextDriver;
  41. flags &= ~(IBDM_REVERSE | IBDM_FIRSTINSTANCEONLY);
  42. }
  43. else
  44. {
  45. if (flags & IBDM_REVERSE)
  46. {
  47. if (!hDriverStart)
  48. hDriverStart = (HDRVR)(idLastDriver+1);
  49. idEnd = lpdt[idFirstDriver].idPrevDriver;
  50. }
  51. else
  52. {
  53. if (!hDriverStart)
  54. hDriverStart = (HDRVR)(idFirstDriver+1);
  55. idEnd = lpdt[idLastDriver].idNextDriver;
  56. }
  57. }
  58. /* Ids are -1 into the global driver list. */
  59. ((int)hDriverStart)--;
  60. for (id = (int)hDriverStart; id != idEnd; id = (flags & IBDM_REVERSE ? lpdt[id].idPrevDriver : lpdt[id].idNextDriver))
  61. {
  62. if (lpdt[id].hModule)
  63. {
  64. if ((flags & IBDM_FIRSTINSTANCEONLY) &&
  65. !lpdt[id].fFirstEntry)
  66. continue;
  67. result =
  68. (*lpdt[id].lpDriverEntryPoint)(lpdt[id].dwDriverIdentifier,
  69. (HDRVR)(id+1),
  70. message,
  71. lParam1,
  72. lParam2);
  73. /* If this isn't a IBDM_SENDMESSAGE, we want to update our end
  74. * points in case the driver callback added or removed some drivers
  75. */
  76. if (flags & IBDM_REVERSE)
  77. {
  78. idEnd = lpdt[idFirstDriver].idPrevDriver;
  79. }
  80. else if (!(flags & IBDM_SENDMESSAGE))
  81. {
  82. idEnd = lpdt[idLastDriver].idNextDriver;
  83. }
  84. else
  85. {
  86. /* This is a IBDM_SENDMESSAGE. We need to break out of the for
  87. * loop here otherwise we run into problems if a new driver was
  88. * installed in the list during the callback and idEnd got
  89. * updated or something...
  90. */
  91. break;
  92. }
  93. }
  94. }
  95. return(result);
  96. }
  97. LRESULT API ISendDriverMessage(HDRVR hDriverID,
  98. UINT message,
  99. LPARAM lParam1,
  100. LPARAM lParam2)
  101. {
  102. return(InternalBroadcastDriverMessage(hDriverID,
  103. message,
  104. lParam1,
  105. lParam2,
  106. IBDM_SENDMESSAGE));
  107. }
  108. BOOL API IGetDriverInfo(HDRVR hDriver, LPDRIVERINFOSTRUCT lpDriverInfoStruct)
  109. {
  110. LPDRIVERTABLE lpdt;
  111. BOOL ret = FALSE;
  112. if (!lpDriverInfoStruct ||
  113. lpDriverInfoStruct->length != sizeof(DRIVERINFOSTRUCT))
  114. {
  115. /* Error in struct size
  116. */
  117. DebugErr(DBF_ERROR, "Invalid size for DRIVERINFOSTRUCT");
  118. return(ret);
  119. }
  120. #ifdef DEBUG
  121. DebugFillStruct(lpDriverInfoStruct, sizeof(DRIVERINFOSTRUCT));
  122. lpDriverInfoStruct->length = sizeof(DRIVERINFOSTRUCT);
  123. #endif
  124. if (!hInstalledDriverList || (int)hDriver <= 0 || (int)hDriver > cInstalledDrivers)
  125. return(ret);
  126. lpdt = (LPDRIVERTABLE)MAKELP(hInstalledDriverList, 0);
  127. if (lpdt[(int)hDriver-1].hModule)
  128. {
  129. lpDriverInfoStruct->hDriver = hDriver;
  130. lpDriverInfoStruct->hModule = lpdt[(int)hDriver-1].hModule;
  131. lstrcpy(lpDriverInfoStruct->szAliasName, lpdt[(int)hDriver-1].szAliasName);
  132. ret = TRUE;
  133. }
  134. return(ret);
  135. }
  136. HDRVR API IGetNextDriver(HDRVR hStart, DWORD dwFlags)
  137. {
  138. int iStart;
  139. int iEnd;
  140. int id;
  141. HDRVR h;
  142. LPDRIVERTABLE lpdt;
  143. if (!hInstalledDriverList || !cInstalledDrivers || idFirstDriver == -1)
  144. return(0);
  145. lpdt = (LPDRIVERTABLE)MAKELP(hInstalledDriverList,0);
  146. if (dwFlags & GND_REVERSE)
  147. {
  148. if (!hStart)
  149. iStart = idLastDriver;
  150. else
  151. {
  152. iStart = (int)hStart-1;
  153. if (iStart == idFirstDriver)
  154. /* If we are at the first driver, nothing left to do
  155. */
  156. return((HDRVR)0);
  157. iStart = lpdt[iStart].idPrevDriver;
  158. }
  159. iEnd = lpdt[idFirstDriver].idPrevDriver;
  160. }
  161. else
  162. {
  163. if (!hStart)
  164. iStart = idFirstDriver;
  165. else
  166. {
  167. iStart = (int)hStart-1;
  168. if (iStart == idLastDriver)
  169. /* If we are at the last driver, nothing left to do.
  170. */
  171. return((HDRVR)0);
  172. iStart = lpdt[iStart].idNextDriver;
  173. }
  174. iEnd = lpdt[idLastDriver].idNextDriver;
  175. }
  176. if (!lpdt[iStart].hModule)
  177. {
  178. /* Bogus driver handle passed in
  179. */
  180. DebugErr(DBF_ERROR, "GetNextDriver: Invalid starting driver handle");
  181. return(0);
  182. }
  183. h = NULL;
  184. for (id = iStart; id != iEnd; id = (dwFlags & GND_REVERSE ? lpdt[id].idPrevDriver : lpdt[id].idNextDriver))
  185. {
  186. if (lpdt[id].hModule)
  187. {
  188. if ((dwFlags & GND_FIRSTINSTANCEONLY) &&
  189. !lpdt[id].fFirstEntry)
  190. continue;
  191. h = (HDRVR)(id+1);
  192. break;
  193. }
  194. }
  195. return(h);
  196. }
  197. LRESULT API IDefDriverProc(dwDriverIdentifier, driverID, message, lParam1, lParam2)
  198. DWORD dwDriverIdentifier;
  199. HDRVR driverID;
  200. UINT message;
  201. LPARAM lParam1;
  202. LPARAM lParam2;
  203. {
  204. switch (message)
  205. {
  206. case DRV_INSTALL:
  207. return((LRESULT)(DWORD)DRVCNF_OK);
  208. break;
  209. case DRV_LOAD:
  210. case DRV_ENABLE:
  211. case DRV_DISABLE:
  212. case DRV_FREE:
  213. return((LRESULT)(DWORD)TRUE);
  214. break;
  215. }
  216. return(0L);
  217. }