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.

256 lines
7.5 KiB

  1. /****************************************************************************
  2. *
  3. * drvproc.c
  4. *
  5. ***************************************************************************/
  6. /**************************************************************************
  7. *
  8. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. * PURPOSE.
  12. *
  13. * Copyright (c) 1991 - 1995 Microsoft Corporation. All Rights Reserved.
  14. *
  15. **************************************************************************/
  16. #include <windows.h>
  17. #include <windowsx.h>
  18. #include <mmsystem.h>
  19. #ifndef _INC_COMPDDK
  20. #define _INC_COMPDDK 50 /* version number */
  21. #endif
  22. #include <vfw.h>
  23. #include "msrle.h"
  24. HMODULE ghModule;
  25. /***************************************************************************
  26. * @doc INTERNAL
  27. *
  28. * @api LRESULT | DriverProc | The entry point for an installable driver.
  29. *
  30. * @parm DWORD | dwDriverId | For most messages, <p dwDriverId> is the DWORD
  31. * value that the driver returns in response to a <m DRV_OPEN> message.
  32. * Each time that the driver is opened, through the <f DrvOpen> API,
  33. * the driver receives a <m DRV_OPEN> message and can return an
  34. * arbitrary, non-zero value. The installable driver interface
  35. * saves this value and returns a unique driver handle to the
  36. * application. Whenever the application sends a message to the
  37. * driver using the driver handle, the interface routes the message
  38. * to this entry point and passes the corresponding <p dwDriverId>.
  39. * This mechanism allows the driver to use the same or different
  40. * identifiers for multiple opens but ensures that driver handles
  41. * are unique at the application interface layer.
  42. *
  43. * The following messages are not related to a particular open
  44. * instance of the driver. For these messages, the dwDriverId
  45. * will always be zero.
  46. *
  47. * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  48. *
  49. * @parm HDRVR | hDriver | This is the handle returned to the
  50. * application by the driver interface.
  51. *
  52. * @parm UINT | uiMessage | The requested action to be performed. Message
  53. * values below <m DRV_RESERVED> are used for globally defined messages.
  54. * Message values from <m DRV_RESERVED> to <m DRV_USER> are used for
  55. * defined driver protocols. Messages above <m DRV_USER> are used
  56. * for driver specific messages.
  57. *
  58. * @parm LPARAM | lParam1 | Data for this message. Defined separately for
  59. * each message
  60. *
  61. * @parm LPARAM | lParam2 | Data for this message. Defined separately for
  62. * each message
  63. *
  64. * @rdesc Defined separately for each message.
  65. ***************************************************************************/
  66. LRESULT FAR PASCAL _loadds DriverProc(DWORD_PTR dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  67. {
  68. PRLEINST pri = dwDriverID != -1 ? (PRLEINST)dwDriverID : NULL;
  69. switch (uiMessage)
  70. {
  71. case DRV_LOAD:
  72. #ifdef _WIN32
  73. if (ghModule) {
  74. // AVI explicitly loads us as well, but does not pass the
  75. // correct (as known by WINMM) driver handle.
  76. } else {
  77. ghModule = (HANDLE) GetDriverModuleHandle(hDriver);
  78. }
  79. #endif
  80. RleLoad();
  81. return (LRESULT)1L;
  82. case DRV_FREE:
  83. RleFree();
  84. return (LRESULT)1L;
  85. case DRV_OPEN:
  86. // if being opened with no open struct, then return a non-zero
  87. // value without actually opening
  88. if (lParam2 == 0L)
  89. return -1l;
  90. return (LRESULT)(DWORD_PTR)(UINT_PTR)RleOpen();
  91. case DRV_CLOSE:
  92. if (pri)
  93. RleClose(pri);
  94. return (LRESULT)1L;
  95. /*********************************************************************
  96. state messages
  97. *********************************************************************/
  98. case ICM_GETSTATE:
  99. return RleGetState(pri, (LPVOID)lParam1, (DWORD)lParam2);
  100. case ICM_SETSTATE:
  101. return RleSetState(pri, (LPVOID)lParam1, (DWORD)lParam2);
  102. case ICM_GETINFO:
  103. return RleGetInfo(pri, (ICINFO FAR *)lParam1, (DWORD)lParam2);
  104. case ICM_GETDEFAULTQUALITY:
  105. if (lParam1)
  106. {
  107. *((LPDWORD)lParam1) = QUALITY_DEFAULT;
  108. return ICERR_OK;
  109. }
  110. break;
  111. /*********************************************************************
  112. compression messages
  113. *********************************************************************/
  114. case ICM_COMPRESS_QUERY:
  115. return RleCompressQuery(pri,
  116. (LPBITMAPINFOHEADER)lParam1,
  117. (LPBITMAPINFOHEADER)lParam2);
  118. case ICM_COMPRESS_BEGIN:
  119. return RleCompressBegin(pri,
  120. (LPBITMAPINFOHEADER)lParam1,
  121. (LPBITMAPINFOHEADER)lParam2);
  122. case ICM_COMPRESS_GET_FORMAT:
  123. return RleCompressGetFormat(pri,
  124. (LPBITMAPINFOHEADER)lParam1,
  125. (LPBITMAPINFOHEADER)lParam2);
  126. case ICM_COMPRESS_GET_SIZE:
  127. return RleCompressGetSize(pri,
  128. (LPBITMAPINFOHEADER)lParam1,
  129. (LPBITMAPINFOHEADER)lParam2);
  130. case ICM_COMPRESS:
  131. return RleCompress(pri,
  132. (ICCOMPRESS FAR *)lParam1, (DWORD)lParam2);
  133. case ICM_COMPRESS_END:
  134. return RleCompressEnd(pri);
  135. /*********************************************************************
  136. decompress messages
  137. *********************************************************************/
  138. case ICM_DECOMPRESS_QUERY:
  139. return RleDecompressQuery(pri,
  140. (LPBITMAPINFOHEADER)lParam1,
  141. (LPBITMAPINFOHEADER)lParam2);
  142. case ICM_DECOMPRESS_BEGIN:
  143. return RleDecompressBegin(pri,
  144. (LPBITMAPINFOHEADER)lParam1,
  145. (LPBITMAPINFOHEADER)lParam2);
  146. case ICM_DECOMPRESS_GET_FORMAT:
  147. return RleDecompressGetFormat(pri,
  148. (LPBITMAPINFOHEADER)lParam1,
  149. (LPBITMAPINFOHEADER)lParam2);
  150. case ICM_DECOMPRESS:
  151. return RleDecompress(pri,
  152. (ICDECOMPRESS FAR *)lParam1, (DWORD)lParam2);
  153. case ICM_DECOMPRESS_END:
  154. return RleDecompressEnd(pri);
  155. /*********************************************************************
  156. standard driver messages
  157. *********************************************************************/
  158. case DRV_DISABLE:
  159. case DRV_ENABLE:
  160. return (LRESULT)1L;
  161. case DRV_INSTALL:
  162. case DRV_REMOVE:
  163. return (LRESULT)DRV_OK;
  164. }
  165. if (uiMessage < DRV_USER)
  166. return DefDriverProc(dwDriverID, hDriver, uiMessage,lParam1,lParam2);
  167. else
  168. return ICERR_UNSUPPORTED;
  169. }
  170. /****************************************************************************
  171. * @doc INTERNAL
  172. *
  173. * @api int | LibMain | Library initialization code.
  174. *
  175. * @parm HANDLE | hModule | Our module handle.
  176. *
  177. * @parm WORD | wHeapSize | The heap size from the .def file.
  178. *
  179. * @parm LPSTR | lpCmdLine | The command line.
  180. *
  181. * @rdesc Returns 1 if the initialization was successful and 0 otherwise.
  182. ***************************************************************************/
  183. #ifndef _WIN32
  184. int NEAR PASCAL LibMain(HMODULE hModule, WORD wHeapSize, LPSTR lpCmdLine)
  185. {
  186. ghModule = hModule;
  187. return 1;
  188. }
  189. #endif
  190. #if 0 // NO DLL load proc needed
  191. // NOTE: ghModule Will be set up on DRV_LOAD call
  192. #ifdef _WIN32
  193. BOOL WINAPI DLLEntryPoint(HINSTANCE hModule, ULONG Reason, LPVOID pv)
  194. {
  195. switch (Reason)
  196. {
  197. case DLL_PROCESS_ATTACH:
  198. ghModule = hModule;
  199. DisableThreadLibraryCalls(hModule);
  200. break;
  201. case DLL_PROCESS_DETACH:
  202. break;
  203. }
  204. return TRUE;
  205. }
  206. #endif
  207. #endif // if 0