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.

185 lines
6.7 KiB

  1. /****************************************************************************
  2. *
  3. * piondrvr.c
  4. *
  5. * Copyright (c) 1991-1993 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * MCI Device Driver for the Pioneer 4200 Videodisc Player
  8. *
  9. * Main Module - Standard Driver Interface and Message Procedures
  10. *
  11. ***************************************************************************/
  12. #include <windows.h>
  13. #include <windowsx.h>
  14. #include <mmsystem.h>
  15. #include <mmddk.h>
  16. #include "mcipionr.h"
  17. #include "pioncnfg.h"
  18. #define CONFIG_ID 10000L /* use hiword of dwDriverID to */
  19. /* identify config. opens */
  20. static WORD wTableEntry; /* custom table ID returned */
  21. /* from mciLoadCommandResource() */
  22. /***************************************************************************
  23. * @doc INTERNAL
  24. *
  25. * @api LRESULT | DriverProc | Windows driver entry point. All Windows driver
  26. * control messages and all MCI messages pass through this entry point.
  27. *
  28. * @parm DWORD | dwDriverId | For most messages, <p dwDriverId> is the DWORD
  29. * value that the driver returns in response to a <m DRV_OPEN> message.
  30. * Each time that the driver is opened, through the <f DrvOpen> API,
  31. * the driver receives a <m DRV_OPEN> message and can return an
  32. * arbitrary, non-zero value. The installable driver interface
  33. * saves this value and returns a unique driver handle to the
  34. * application. Whenever the application sends a message to the
  35. * driver using the driver handle, the interface routes the message
  36. * to this entry point and passes the corresponding <p dwDriverId>.
  37. * This mechanism allows the driver to use the same or different
  38. * identifiers for multiple opens but ensures that driver handles
  39. * are unique at the application interface layer.
  40. *
  41. * The following messages are not related to a particular open
  42. * instance of the driver. For these messages, the dwDriverId
  43. * will always be zero.
  44. *
  45. * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  46. *
  47. * @parm HDRVR | hDriver | This is the handle returned to the
  48. * application by the driver interface.
  49. *
  50. * @parm UINT | message | The requested action to be performed. Message
  51. * values below <m DRV_RESERVED> are used for globally defined messages.
  52. * Message values from <m DRV_RESERVED> to <m DRV_USER> are used for
  53. * defined driver protocols. Messages above <m DRV_USER> are used
  54. * for driver specific messages.
  55. *
  56. * @parm LPARAM | lParam1 | Data for this message. Defined separately for
  57. * each message
  58. *
  59. * @parm LPARAM | lParam2 | Data for this message. Defined separately for
  60. * each message
  61. *
  62. * @rdesc Defined separately for each message.
  63. ***************************************************************************/
  64. LRESULT FAR PASCAL _LOADDS DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT message, LPARAM lParam1, LPARAM lParam2)
  65. {
  66. DWORD dwRes = 0L;
  67. TCHAR aszResource[32];
  68. switch (message) {
  69. case DRV_LOAD:
  70. /* the DRV_LOAD message is received once, when the driver is */
  71. /* first loaded - any one-time initialization code goes here */
  72. /* load the custom command table */
  73. LoadString(hInstance,IDS_COMMANDS,aszResource,sizeof(aszResource));
  74. wTableEntry = mciLoadCommandResource(hInstance, aszResource, 0);
  75. /* return 0L to FAIL the load. */
  76. dwRes = wTableEntry != MCI_NO_COMMAND_TABLE;
  77. break;
  78. case DRV_FREE:
  79. /* the DRV_FREE message is received once when the driver is */
  80. /* unloaded - any final shut down code goes here */
  81. /* free the custom command table */
  82. mciFreeCommandResource(wTableEntry);
  83. dwRes = 1L;
  84. break;
  85. case DRV_OPEN:
  86. /* the DRV_OPEN message is received once for each MCI device open */
  87. /* configuration open case */
  88. if (!lParam2)
  89. dwRes = CONFIG_ID;
  90. /* normal case */
  91. else {
  92. LPMCI_OPEN_DRIVER_PARMS lpOpen =
  93. (LPMCI_OPEN_DRIVER_PARMS)lParam2;
  94. UINT Port;
  95. UINT Rate;
  96. /* associate the channel number with the driver ID */
  97. pionGetComportAndRate((LPTSTR)lpOpen->lpstrParams, &Port, &Rate);
  98. pionSetBaudRate(Port, Rate);
  99. mciSetDriverData(lpOpen->wDeviceID, (DWORD)Port);
  100. /* specify the custom command table and the device type */
  101. lpOpen->wCustomCommandTable = wTableEntry;
  102. lpOpen->wType = MCI_DEVTYPE_VIDEODISC;
  103. /* return the device ID to be used in subsequent */
  104. /* messages or 0 to fail the open */
  105. dwRes = lpOpen->wDeviceID;
  106. break;
  107. }
  108. case DRV_CLOSE:
  109. /* this message is received once for each MCI device close */
  110. dwRes = 1L;
  111. break;
  112. case DRV_ENABLE:
  113. /* the DRV_ENABLE message is received when the driver is loaded */
  114. /* or reloaded and whenever windows is enabled */
  115. dwRes = 1L;
  116. break;
  117. case DRV_DISABLE:
  118. /* the DRV_DISABLE message is received before the driver is */
  119. /* freed and whenever windows is disabled */
  120. dwRes = 1L;
  121. break;
  122. case DRV_QUERYCONFIGURE:
  123. /* the DRV_QUERYCONFIGURE message is used to determine if the */
  124. /* DRV_CONCIGURE message is supported - return 1 to indicate */
  125. /* configuration IS supported. */
  126. dwRes = 1L;
  127. break;
  128. case DRV_CONFIGURE:
  129. /* the DRV_CONFIGURE message instructs the device to perform */
  130. /* device configuration. */
  131. if (lParam2 && lParam1 && (((LPDRVCONFIGINFO)lParam2)->dwDCISize == sizeof(DRVCONFIGINFO)))
  132. dwRes = pionConfig((HWND)lParam1, (LPDRVCONFIGINFO)lParam2);
  133. else
  134. dwRes = DRVCNF_CANCEL;
  135. break;
  136. default:
  137. /* all other messages are processed here */
  138. /* select messages in the MCI range */
  139. if (!HIWORD(dwDriverID) &&
  140. message >= DRV_MCI_FIRST && message <= DRV_MCI_LAST ||
  141. message >= VDISC_FIRST && message <= VDISC_LAST)
  142. dwRes = mciDriverEntry((WORD)dwDriverID, message,
  143. lParam1, lParam2);
  144. /* other messages get default processing */
  145. else
  146. dwRes = DefDriverProc(dwDriverID, hDriver, message,
  147. lParam1, lParam2);
  148. break;
  149. }
  150. return (LRESULT)dwRes;
  151. }