Kernel32DeviceIoControl(SafeFileHandle, DirectoryManagementControlCodes, IntPtr, Int32, IntPtr, Int32, Int32, IntPtr) Method
Sends a control code directly to a specified device driver,
causing the corresponding device to perform the corresponding operation.
Namespace: DevCase.Win32.NativeMethodsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static bool DeviceIoControl(
SafeFileHandle hDevice,
DirectoryManagementControlCodes ioControlCode,
[OptionalAttribute] IntPtr inputBuffer,
[OptionalAttribute] int inputBufferSize,
[OptionalAttribute] IntPtr outputBuffer,
[OptionalAttribute] int outputBufferSize,
out int refBytesReturned,
[OptionalAttribute] IntPtr overlapped
)
<DllImportAttribute("Kernel32.dll", CharSet := CharSet.Auto, SetLastError := true>]
Public Shared Function DeviceIoControl (
hDevice As SafeFileHandle,
ioControlCode As DirectoryManagementControlCodes,
<OptionalAttribute> inputBuffer As IntPtr,
<OptionalAttribute> inputBufferSize As Integer,
<OptionalAttribute> <OutAttribute> outputBuffer As IntPtr,
<OptionalAttribute> outputBufferSize As Integer,
<OutAttribute> ByRef refBytesReturned As Integer,
<OptionalAttribute> <OutAttribute> overlapped As IntPtr
) As Boolean
Dim hDevice As SafeFileHandle
Dim ioControlCode As DirectoryManagementControlCodes
Dim inputBuffer As IntPtr
Dim inputBufferSize As Integer
Dim outputBuffer As IntPtr
Dim outputBufferSize As Integer
Dim refBytesReturned As Integer
Dim overlapped As IntPtr
Dim returnValue As Boolean
returnValue = Kernel32.DeviceIoControl(hDevice,
ioControlCode, inputBuffer, inputBufferSize,
outputBuffer, outputBufferSize,
refBytesReturned, overlapped)
public:
[DllImportAttribute(L"Kernel32.dll", CharSet = CharSet::Auto, SetLastError = true)]
static bool DeviceIoControl(
SafeFileHandle^ hDevice,
DirectoryManagementControlCodes ioControlCode,
[OptionalAttribute] [InAttribute] IntPtr inputBuffer,
[OptionalAttribute] [InAttribute] int inputBufferSize,
[OptionalAttribute] [OutAttribute] IntPtr outputBuffer,
[OptionalAttribute] [InAttribute] int outputBufferSize,
[OutAttribute] int% refBytesReturned,
[OptionalAttribute] [InAttribute] [OutAttribute] IntPtr overlapped
)
[<DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
static member DeviceIoControl :
hDevice : SafeFileHandle *
ioControlCode : DirectoryManagementControlCodes *
[<OptionalAttribute>] inputBuffer : IntPtr *
[<OptionalAttribute>] inputBufferSize : int *
[<OptionalAttribute>] outputBuffer : IntPtr byref *
[<OptionalAttribute>] outputBufferSize : int *
refBytesReturned : int byref *
[<OptionalAttribute>] overlapped : IntPtr byref -> bool
No code example is currently available or this language may not be supported.
- hDevice SafeFileHandle
-
A handle to the device on which the operation is to be performed.
The device is typically a volume, directory, file, or stream.
To retrieve a device handle, use the CreateFile(String, FileAccessRights, FileShare, IntPtr, FileMode, CreateFileFlags, IntPtr) function.
- ioControlCode DirectoryManagementControlCodes
-
The directory management control code for the operation.
- inputBuffer IntPtr (Optional)
-
A pointer to the input buffer that contains the data required to perform the operation.
The format of this data depends on the value of the ioControlCode parameter.
This parameter can be if
ioControlCode parameter specifies an operation that does not require input data.
- inputBufferSize Int32 (Optional)
-
The size of the input buffer specified in the inputBuffer parameter, in bytes.
- outputBuffer IntPtr (Optional)
-
A pointer to the output buffer that is to receive the data returned by the operation.
The format of this data depends on the value of the dwIoControlCode parameter.
This parameter can be if
ioControlCode parameter specifies an operation that does not return data.
- outputBufferSize Int32 (Optional)
-
The size of the input buffer specified in the outputBuffer parameter, in bytes.
- refBytesReturned Int32
-
A pointer to a variable that receives the size of the data stored in the
output buffer of outputBuffer parameter, in bytes.
If the output buffer is too small to receive any data, the call fails,
GetLastWin32Error returns ERROR_INSUFFICIENT_BUFFER,
and refBytesReturned is zero.
If the output buffer is too small to hold all of the data but can hold some entries,
some drivers will return as much data as fits.
In this case, the call fails, GetLastWin32Error returns
ERROR_MORE_DATA, and refBytesReturned indicates the
amount of data received.
Your application should call DeviceIoControl(SafeFileHandle, DirectoryManagementControlCodes, IntPtr, Int32, IntPtr, Int32, Int32, IntPtr) again with the same operation,
specifying a new starting point.
If overlapped is ,
refBytesReturned cannot be .
Even when an operation returns no output data and outputBuffer is ,
DeviceIoControl(SafeFileHandle, DirectoryManagementControlCodes, IntPtr, Int32, IntPtr, Int32, Int32, IntPtr) makes use of refBytesReturned.
After such an operation, the value of refBytesReturned is meaningless.
If overlapped is not ,
refBytesReturned can be .
If this parameter is not and the operation returns data,
refBytesReturned is meaningless until the overlapped operation has completed.
To retrieve the number of bytes returned, call GetOverlappedResult function.
If hDevice is associated with an I/O completion port,
you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus function.
- overlapped IntPtr (Optional)
-
A pointer to an OVERLAPPED structure.
If hDevice was opened without specifying Overlapped flag,
overlapped parameter is ignored.
If hDevice was opened with the Overlapped flag,
the operation is performed as an overlapped (asynchronous) operation.
In this case, overlapped parameter must point to a valid OVERLAPPED structure
that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.
For overlapped operations, DeviceIoControl(SafeFileHandle, DirectoryManagementControlCodes, IntPtr, Int32, IntPtr, Int32, Int32, IntPtr) returns immediately,
and the event object is signaled when the operation has been completed.
Otherwise, the function does not return until the operation has been completed or an error occurs.
Boolean
If the operation completes successfully, the return value is
.
If the operation fails or is pending, the return value is
.
To get extended error information, call
GetLastWin32Error.