pywincffi.kernel32 package¶
Submodules¶
pywincffi.kernel32.io module¶
Files¶
A module containing common Windows file functions.
-
pywincffi.kernel32.io.
CloseHandle
(hObject)[source]¶ Closes an open object handle.
Parameters: hObject (handle) – The handle object to close.
-
pywincffi.kernel32.io.
CreatePipe
(nSize=0, lpPipeAttributes=None)[source]¶ Creates an anonymous pipe and returns the read and write handles.
See also
https://msdn.microsoft.com/en-us/library/aa365152 https://msdn.microsoft.com/en-us/library/aa379560
>>> from pywincffi.core import dist >>> ffi, library = dist.load() >>> lpPipeAttributes = ffi.new( ... "SECURITY_ATTRIBUTES[1]", [{ ... "nLength": ffi.sizeof("SECURITY_ATTRIBUTES"), ... "bInheritHandle": True, ... "lpSecurityDescriptor": ffi.NULL ... }] ... ) >>> reader, writer = CreatePipe(lpPipeAttributes=lpPipeAttributes)
Parameters: - nSize (int) – The size of the buffer in bytes. Passing in 0, which is the default will cause the system to use the default buffer size.
- lpPipeAttributes – The security attributes to apply to the handle. By default
NULL
will be passed in meaning then handle we create cannot be inherited. For more detailed information see the links below.
Returns: Returns a tuple of handles containing the reader and writer ends of the pipe that was created. The user of this function is responsible for calling CloseHandle at some point.
-
pywincffi.kernel32.io.
GetStdHandle
(nStdHandle)[source]¶ Retrieves a handle to the specified standard device (standard input, standard output, or standard error).
Parameters: nStdHandle (int) – The standard device to retrieve Return type: handle Returns: Returns a handle to the standard device retrieved.
-
pywincffi.kernel32.io.
PeekNamedPipe
(hNamedPipe, nBufferSize)[source]¶ Copies data from a pipe into a buffer without removing it from the pipe.
Parameters: - hNamedPipe (handle) – The handele to the pipe object we want to peek into.
- nBufferSize (int) – The number of bytes to ‘peek’ into the pipe.
Return type: Returns: Returns an instance of
PeekNamedPipeResult
which contains the buffer read, number of bytes read and the result.
-
class
pywincffi.kernel32.io.
PeekNamedPipeResult
(lpBuffer, lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage)¶ Bases:
tuple
-
lpBuffer
¶ Alias for field number 0
-
lpBytesLeftThisMessage
¶ Alias for field number 3
-
lpBytesRead
¶ Alias for field number 1
-
lpTotalBytesAvail
¶ Alias for field number 2
-
-
pywincffi.kernel32.io.
ReadFile
(hFile, nNumberOfBytesToRead, lpOverlapped=None)[source]¶ Read the specified number of bytes from
hFile
.Parameters: - hFile (handle) – The handle to read from
- nNumberOfBytesToRead (int) – The number of bytes to read from
hFile
- lpOverlapped (None or OVERLAPPED) –
None or a pointer to a
OVERLAPPED
structure. See Microsoft’s documentation for intended usage and below for an example of this struct.>>> from pywincffi.core import dist >>> ffi, library = dist.load() >>> hFile = None # normally, this would be a handle >>> lpOverlapped = ffi.new( ... "OVERLAPPED[1]", [{ ... "hEvent": hFile ... }] ... ) >>> read_data = ReadFile( # read 12 bytes from hFile ... hFile, 12, lpOverlapped=lpOverlapped)
Returns: Returns the data read from
hFile
-
pywincffi.kernel32.io.
SetNamedPipeHandleState
(hNamedPipe, lpMode=None, lpMaxCollectionCount=None, lpCollectDataTimeout=None)[source]¶ Sets the read and blocking mode of the specified
hNamedPipe
.Parameters: - hNamedPipe (handle) – A handle to the named pipe instance.
- lpMode (int) –
The new pipe mode which is a combination of read mode:
PIPE_READMODE_BYTE
PIPE_READMODE_MESSAGE
And a wait-mode flag:
PIPE_WAIT
PIPE_NOWAIT
- lpMaxCollectionCount (int) – The maximum number of bytes collected.
- lpCollectDataTimeout (int) – The maximum time, in milliseconds, that can pass before a remote named pipe transfers information
-
pywincffi.kernel32.io.
WriteFile
(hFile, lpBuffer, lpOverlapped=None)[source]¶ Writes data to
hFile
which may be an I/O device for file.Parameters: - hFile (handle) – The handle to write to
- lpBuffer (bytes, string or unicode.) – The data to be written to the file or device. We should be able to convert this value to unicode.
- lpOverlapped (None or OVERLAPPED) –
None or a pointer to a
OVERLAPPED
structure. See Microsoft’s documentation for intended usage and below for an example of this struct.>>> from pywincffi.core import dist >>> ffi, library = dist.load() >>> hFile = None # normally, this would be a handle >>> lpOverlapped = ffi.new( ... "OVERLAPPED[1]", [{ ... "hEvent": hFile ... }] ... ) >>> bytes_written = WriteFile( ... hFile, "Hello world", lpOverlapped=lpOverlapped)
Returns: Returns the number of bytes written
-
pywincffi.kernel32.io.
handle_from_file
(python_file)[source]¶ Given a standard Python file object produce a Windows handle object that be be used in Windows function calls.
Parameters: python_file (file) – The Python file object to convert to a Windows handle. Returns: Returns a Windows handle object which is pointing at the provided python_file
object.
pywincffi.kernel32.process module¶
Process¶
Provides functions, constants and utilities that wrap the Windows functions associated with process management and interaction. This module also provides several constants as well, see Microsoft’s documentation for the constant names and their purpose:
- Process Security and Access Rights - https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880
Note
Not all constants may be defined