|
Overview |
|
|
|
Group |
|
|
|
Quick Info
Windows NT
| Yes
| Win95
| Yes
| Win32s
| No
| Import Library
| kernel32.lib
| Header File
| winbase.h
| Unicode
| No
| Platform Notes
| None
|
|
|
DeviceIoControl
The DeviceIoControl function sends a control code directly to a specified device driver, causing
the corresponding device to perform the specified operation.
BOOL DeviceIoControl(
HANDLE hDevice,
| // handle to device of interest
| DWORD dwIoControlCode,
| // control code of operation to perform
| LPVOID lpInBuffer,
| // pointer to buffer to supply input data
| DWORD nInBufferSize,
| // size of input buffer
| LPVOID lpOutBuffer,
| // pointer to buffer to receive output data
| DWORD nOutBufferSize,
| // size of output buffer
| LPDWORD lpBytesReturned,
| // pointer to variable to receive output byte count
| LPOVERLAPPED lpOverlapped
| // pointer to overlapped structure for asynchronous operation
| );
|
|
Parameters
hDevice
Handle to the device that is to perform the operation. Call the CreateFile function to obtain a device handle.
dwIoControlCode
Specifies the control code for the operation. This value identifies the
specific operation to be performed and the type of device on which the operation is
to be performed. The following values are defined:
For more detailed information on each control code, see its topic. In
particular, each topic provides details on the usage of the lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, and lpBytesReturned parameters.
lpInBuffer
Pointer to a buffer that contains the data required to perform the operation.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not require input data.
nInBufferSize
Specifies the size, in bytes, of the buffer pointed to by lpInBuffer.
lpOutBuffer
Pointer to a buffer that receives the operation's output data.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.
nOutBufferSize
Specifies the size, in bytes, of the buffer pointed to by lpOutBuffer.
lpBytesReturned
Pointer to a variable that receives the size, in bytes, of the data stored
into the buffer pointed to by lpOutBuffer.
If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation produces no output data, and lpOutBuffer can be NULL, the DeviceIoControl function makes use of the variable pointed to by lpBytesReturned. After such an operation, the value of the variable is without meaning.
If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this is an overlapped operation, you can get the number of
bytes returned by calling GetOverlappedResult. If hDevice is associated with an I/O completion port, you can get the number of bytes
returned by calling GetQueuedCompletionStatus.
lpOverlapped
Pointer to an OVERLAPPED structure.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, this parameter must point to a
valid OVERLAPPED structure. In this case, DeviceIoControl is performed as an overlapped (asynchronous) operation. If the device was
opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function fails in unpredictable ways.
If hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag, this parameter
is ignored and the DeviceIoControl function does not return until the operation has been completed, or an error
occurs.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
If hDevice was opened with FILE_FLAG_OVERLAPPED and the lpOverlapped parameter points to an OVERLAPPED structure, DeviceIoControl is performed as an overlapped (asynchronous) operation. In this case, the OVERLAPPED structure must contain a handle to a manual-reset event object created by a
call to the CreateEvent function. For more information on manual-reset event objects, see Synchronization.
If the overlapped operation cannot be completed immediately, the function
returns FALSE, and GetLastError returns ERROR_IO_PENDING, indicating that the operation is executing in the
background. When this happens, the operating system sets the event object in the OVERLAPPED structure to the nonsignaled state before DeviceIoControl returns. The system then sets the event object to the signaled state when the
operation has been completed. The calling thread can use any of the wait
functions to wait for the event object to be signaled, and then use the GetOverlappedResult function to determine the results of the operation. The GetOverlappedResult function reports the success or failure of the operation and the number of
bytes returned in the lpOutBuffer buffer.
See Also
CreateEvent, CreateFile, GetOverlappedResult, GetQueuedCompletionStatus, OVERLAPPED
Related Links
Software for Delphi and C++ Builder developers
Software for Visual Studio .NET developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET
TMS Scripter Studio Pro components for Delphi/C++Builder
More Online Helps
Win32 Multimedia Programmer's Reference (mmedia.hlp)
OLE Programmer's Reference (ole.hlp)
Microsoft Windows Pen API Programmer's Reference (penapi.hlp)
Microsoft Windows Sockets 2 Reference (sock2.hlp)
Microsoft Windows Telephony API (TAPI) Programmer's Reference (tapi.hlp)
Unix Manual Pages
|