Leaked source code of windows server 2003
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.

251 lines
5.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. vxd32.c
  7. This module contains the Win32-dependent VxD interface.
  8. The following functions are exported by this module:
  9. OsOpenVxdHandle
  10. OsCloseVxdHandle
  11. OsSubmitVxdRequest
  12. FILE HISTORY:
  13. KeithMo 16-Jan-1994 Created.
  14. */
  15. #include "stdafx.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //
  20. // Private constants.
  21. //
  22. #define DLL_ASSERT ASSERT
  23. //
  24. // Private types.
  25. //
  26. //
  27. // Private globals.
  28. //
  29. #ifdef DEBUG
  30. DWORD LastVxdOpcode;
  31. LPVOID LastVxdParam;
  32. DWORD LastVxdParamLength;
  33. #endif // DEBUG
  34. //
  35. // Private prototypes.
  36. //
  37. //
  38. // Public functions.
  39. //
  40. /*******************************************************************
  41. NAME: OsOpenVxdHandle
  42. SYNOPSIS: Opens a handle to the specified VxD.
  43. ENTRY: VxdName - The ASCII name of the target VxD.
  44. VxdId - The unique ID of the target VxD.
  45. RETURNS: DWORD - A handle to the target VxD if successful,
  46. 0 if not.
  47. HISTORY:
  48. KeithMo 16-Jan-1994 Created.
  49. DavidKa 18-Apr-1994 Dynamic load.
  50. ********************************************************************/
  51. DWORD
  52. OsOpenVxdHandle(
  53. CHAR* VxdName,
  54. WORD VxdId
  55. )
  56. {
  57. HANDLE VxdHandle;
  58. CHAR VxdPath[MAX_PATH];
  59. static CONST CHAR VxDPathString[] = "\\\\.\\";
  60. static CONST CHAR VxDExtString[] = ".VXD";
  61. CONST SIZE_T Remaining = sizeof( VxdPath ) -
  62. sizeof( VxDPathString ) -
  63. sizeof( VxDExtString ) +
  64. 1;
  65. //
  66. // Sanity check.
  67. //
  68. DLL_ASSERT( VxdName != NULL );
  69. DLL_ASSERT( VxdId != 0 );
  70. if ( strlen( VxdName ) >= Remaining )
  71. return 0;
  72. //
  73. // Build the VxD path.
  74. //
  75. strcpy( VxdPath, VxDPathString);
  76. strcat( VxdPath, VxdName);
  77. //
  78. // Open the device.
  79. //
  80. // First try the name without the .VXD extension. This will
  81. // cause CreateFile to connect with the VxD if it is already
  82. // loaded (CreateFile will not load the VxD in this case).
  83. //
  84. VxdHandle = CreateFileA( VxdPath,
  85. GENERIC_READ | GENERIC_WRITE,
  86. FILE_SHARE_READ | FILE_SHARE_WRITE,
  87. NULL,
  88. OPEN_EXISTING,
  89. FILE_FLAG_DELETE_ON_CLOSE,
  90. NULL );
  91. if( VxdHandle == INVALID_HANDLE_VALUE )
  92. {
  93. //
  94. // Not found. Append the .VXD extension and try again.
  95. // This will cause CreateFile to load the VxD.
  96. //
  97. strcat( VxdPath, VxDExtString );
  98. VxdHandle = CreateFileA( VxdPath,
  99. GENERIC_READ | GENERIC_WRITE,
  100. FILE_SHARE_READ | FILE_SHARE_WRITE,
  101. NULL,
  102. OPEN_EXISTING,
  103. FILE_FLAG_DELETE_ON_CLOSE,
  104. NULL );
  105. }
  106. if( VxdHandle != INVALID_HANDLE_VALUE )
  107. {
  108. return (DWORD)VxdHandle;
  109. }
  110. return 0;
  111. } // OsOpenVxdHandle
  112. /*******************************************************************
  113. NAME: OsCloseVxdHandle
  114. SYNOPSIS: Closes an open VxD handle.
  115. ENTRY: VxdHandle - The open VxD handle to close.
  116. HISTORY:
  117. KeithMo 16-Jan-1994 Created.
  118. ********************************************************************/
  119. VOID
  120. OsCloseVxdHandle(
  121. DWORD VxdHandle
  122. )
  123. {
  124. //
  125. // Sanity check.
  126. //
  127. DLL_ASSERT( VxdHandle != 0 );
  128. CloseHandle( (HANDLE)VxdHandle );
  129. } // OsCloseVxdHandle
  130. /*******************************************************************
  131. NAME: OsSubmitVxdRequest
  132. SYNOPSIS: Submits a request to the specified VxD.
  133. ENTRY: VxdHandle - An open VxD handle.
  134. OpCode - Specifies the operation to perform.
  135. Param - Points to operation-specific parameters.
  136. ParamLength - The size (in BYTEs) of *Param.
  137. RETURNS: INT - Result code. 0 if successful, !0 if not.
  138. HISTORY:
  139. KeithMo 16-Jan-1994 Created.
  140. ********************************************************************/
  141. INT
  142. OsSubmitVxdRequest(
  143. DWORD VxdHandle,
  144. INT OpCode,
  145. LPVOID Param,
  146. INT ParamLength
  147. )
  148. {
  149. DWORD BytesRead;
  150. INT Result = 0;
  151. //
  152. // Sanity check.
  153. //
  154. DLL_ASSERT( VxdHandle != 0 );
  155. DLL_ASSERT( ( Param != NULL ) || ( ParamLength == 0 ) );
  156. #ifdef DEBUG
  157. LastVxdOpcode = (DWORD)OpCode;
  158. LastVxdParam = Param;
  159. LastVxdParamLength = (DWORD)ParamLength;
  160. #endif // DEBUG
  161. //
  162. // Just do it.
  163. //
  164. if( !DeviceIoControl( (HANDLE)VxdHandle,
  165. OpCode,
  166. Param,
  167. ParamLength,
  168. Param,
  169. ParamLength,
  170. &BytesRead,
  171. NULL ) )
  172. {
  173. Result = GetLastError();
  174. }
  175. return Result;
  176. } // OsSubmitVxdRequest
  177. #ifdef __cplusplus
  178. }
  179. #endif