C# Class PInvoke.Kernel32

Exported functions from the Kernel32.dll Windows library.
Datei anzeigen Open project: AArnott/pinvoke

Public Properties

Property Type Description
INVALID_HANDLE_VALUE System.IntPtr

Public Methods

Method Description
FormatMessage ( FormatMessageFlags dwFlags, void lpSource, int dwMessageId, int dwLanguageId, IntPtr Arguments, int maxAllowedBufferSize ) : string

Formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function. It can come from a message table resource in an already-loaded module. Or the caller can ask the function to search the system's message table resource(s) for the message definition. The function finds the message definition in a message table resource based on a message identifier and a language identifier. The function copies the formatted message text to an output buffer, processing any embedded insert sequences if requested.

GetLastError ( ) : Win32ErrorCode

Returns the error code returned by the last unmanaged function that was called using platform invoke that has the DllImportAttribute.SetLastError flag set.

This method exists because it is not safe to make a direct platform invoke call to GetLastError to obtain this information. If you want to access this error code, you must call GetLastError instead of writing your own platform invoke definition for GetLastError and calling it. The common language runtime can make internal calls to APIs that overwrite the GetLastError maintained by the operating system.

You can use this method to obtain error codes only if you apply the DllImportAttribute to the method signature and set the DllImportAttribute.SetLastError field to true. The process for this varies depending upon the source language used: C# and C++ are false by default, but the Declare statement in Visual Basic is true.

IsWow64Process ( SafeObjectHandle hProcess ) : bool
LocalAlloc ( LocalAllocFlags uFlags, int uBytes ) : void*

Allocates the specified number of bytes from the heap.

LocalReAlloc ( void hMem, int uBytes, LocalReAllocFlags uFlags ) : void*

Changes the size or the attributes of a specified local memory object. The size can increase or decrease.

If LocalReAlloc fails, the original memory is not freed, and the original handle and pointer are still valid. If LocalReAlloc reallocates a fixed object, the value of the handle returned is the address of the first byte of the memory block. To access the memory, a process can simply cast the return value to a pointer.

MAKELANGID ( LANGID ePrimaryLanguage, LANGID eSubLanguage ) : LANGID

Creates a language identifier from a primary language identifier and a sublanguage identifier.

MAKELANGID ( ushort usPrimaryLanguage, ushort usSubLanguage ) : LANGID

Creates a language identifier from a primary language identifier and a sublanguage identifier.

Module32Enumerate ( SafeObjectHandle hSnapshot ) : IEnumerable

Retrieves information about next module encountered in a system snapshot.

Module32First ( SafeObjectHandle hSnapshot ) : MODULEENTRY32?

Retrieves information about the first module encountered in a system snapshot.

Module32Next ( SafeObjectHandle hSnapshot ) : MODULEENTRY32?

Retrieves information about the next module encountered in a system snapshot.

Process32Enumerate ( SafeObjectHandle hSnapshot ) : IEnumerable

Retrieves information about next process encountered in a system snapshot.

Process32First ( SafeObjectHandle hSnapshot ) : PROCESSENTRY32?

Retrieves information about the first process encountered in a system snapshot.

Process32Next ( SafeObjectHandle hSnapshot ) : PROCESSENTRY32?

Retrieves information about the next process encountered in a system snapshot.

QueryFullProcessImageName ( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags = QueryFullProcessImageNameFlags.None ) : string
ReadFile ( SafeObjectHandle hFile, int nNumberOfBytesToRead ) : ArraySegment

Reads data synchronously from the specified file or input/output (I/O) device.

ReadFile ( SafeObjectHandle hFile, ArraySegment lpBuffer ) : int

Reads data synchronously from the specified file or input/output (I/O) device.

ReadFile ( SafeObjectHandle hFile, void lpBuffer, int nNumberOfBytesToRead ) : int

Reads data synchronously from the specified file or input/output (I/O) device.

WriteFile ( SafeObjectHandle hFile, ArraySegment lpBuffer ) : int

Writes data synchronously to the specified file or input/output (I/O) device.

WriteFile ( SafeObjectHandle hFile, void lpBuffer, int nNumberOfBytesToWrite ) : int

Writes data synchronously to the specified file or input/output (I/O) device.

Private Methods

Method Description
CancelIoEx ( SafeObjectHandle hFile, OVERLAPPED lpOverlapped ) : bool
CloseHandle ( IntPtr hObject ) : bool
CreateMutex ( [ lpMutexAttributes, [ bInitialOwner, string lpName ) : SafeObjectHandle
DeviceIoControl ( SafeObjectHandle hDevice, int dwIoControlCode, void inBuffer, int nInBufferSize, void outBuffer, int nOutBufferSize, int &pBytesReturned, OVERLAPPED lpOverlapped ) : bool
FindClose ( IntPtr hFindFile ) : bool
FindFirstFileEx ( string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, WIN32_FIND_DATA &lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, void lpSearchFilter, FindFirstFileExFlags dwAdditionalFlags ) : SafeFindFilesHandle
FlushFileBuffers ( SafeObjectHandle hFile ) : bool
FormatMessage ( FormatMessageFlags dwFlags, void lpSource, int dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr Arguments ) : int
FreeLibrary ( IntPtr hModule ) : bool
GetCurrentProcess ( ) : SafeObjectHandle
GetCurrentProcessId ( ) : int
GetCurrentThreadId ( ) : int
GetProcAddress ( SafeLibraryHandle hModule, string procName ) : IntPtr
GetSystemTime ( [ lpSystemTime ) : void
GetTickCount ( ) : uint
GetTickCount64 ( ) : ulong
LoadResource ( SafeLibraryHandle hModule, IntPtr hResInfo ) : IntPtr
LockResource ( IntPtr hResData ) : void*
ReadFile ( SafeObjectHandle hFile, void lpBuffer, int nNumberOfBytesToRead, [ lpNumberOfBytesRead, OVERLAPPED lpOverlapped ) : bool
ResumeThread ( SafeObjectHandle hThread ) : int
SetSystemTime ( [ lpSystemTime ) : bool
SuspendThread ( SafeObjectHandle hThread ) : int
TryGetErrorMessage ( FormatMessageFlags flags, void source, int messageId, int languageId, StringBuilder sb, IntPtr arguments, string &errorMsg ) : bool

Tries to get the error message text using the supplied buffer.

WaitForSingleObject ( SafeHandle hHandle, int dwMilliseconds ) : WaitForSingleObjectResult
WriteFile ( SafeObjectHandle hFile, void lpBuffer, int nNumberOfBytesToWrite, [ lpNumberOfBytesWritten, OVERLAPPED lpOverlapped ) : bool

Method Details

FormatMessage() public static method

Formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function. It can come from a message table resource in an already-loaded module. Or the caller can ask the function to search the system's message table resource(s) for the message definition. The function finds the message definition in a message table resource based on a message identifier and a language identifier. The function copies the formatted message text to an output buffer, processing any embedded insert sequences if requested.
public static FormatMessage ( FormatMessageFlags dwFlags, void lpSource, int dwMessageId, int dwLanguageId, IntPtr Arguments, int maxAllowedBufferSize ) : string
dwFlags FormatMessageFlags /// The formatting options, and how to interpret the lpSource parameter. The low-order byte of dwFlags specifies how the function handles line breaks in the output buffer. The low-order byte can also specify the maximum width of a formatted output line. /// The flag is always added /// and the flag is always suppressed by this helper method ///
lpSource void /// The location of the message definition. The type of this parameter depends upon the settings in the parameter. /// If : A handle to the module that contains the message table to search. /// If : Pointer to a string that consists of unformatted message text. It will be scanned for inserts and formatted accordingly. /// If neither of these flags is set in dwFlags, then lpSource is ignored. ///
dwMessageId int /// The message identifier for the requested message. This parameter is ignored if dwFlags includes . ///
dwLanguageId int /// The language identifier for the requested message. This parameter is ignored if dwFlags includes . /// If you pass a specific LANGID in this parameter, FormatMessage will return a message for that LANGID only.If the function cannot find a message for that LANGID, it sets Last-Error to ERROR_RESOURCE_LANG_NOT_FOUND.If you pass in zero, FormatMessage looks for a message for LANGIDs in the following order: /// Language neutral /// Thread LANGID, based on the thread's locale value /// User default LANGID, based on the user's default locale value /// System default LANGID, based on the system default locale value /// US English /// If FormatMessage does not locate a message for any of the preceding LANGIDs, it returns any language message string that is present.If that fails, it returns ERROR_RESOURCE_LANG_NOT_FOUND. ///
Arguments System.IntPtr /// An array of values that are used as insert values in the formatted message. A %1 in the format string indicates the first value in the Arguments array; a %2 indicates the second argument; and so on. /// The interpretation of each value depends on the formatting information associated with the insert in the message definition.The default is to treat each value as a pointer to a null-terminated string. /// By default, the Arguments parameter is of type va_list*, which is a language- and implementation-specific data type for describing a variable number of arguments.The state of the va_list argument is undefined upon return from the function.To use the va_list again, destroy the variable argument list pointer using va_end and reinitialize it with va_start. /// If you do not have a pointer of type va_list*, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array of DWORD_PTR values; those values are input to the message formatted as the insert values.Each insert must have a corresponding element in the array. ///
maxAllowedBufferSize int The maximum size of the returned string. If exceeded, null is returned.
return string

GetLastError() public static method

Returns the error code returned by the last unmanaged function that was called using platform invoke that has the DllImportAttribute.SetLastError flag set.
This method exists because it is not safe to make a direct platform invoke call to GetLastError to obtain this information. If you want to access this error code, you must call GetLastError instead of writing your own platform invoke definition for GetLastError and calling it. The common language runtime can make internal calls to APIs that overwrite the GetLastError maintained by the operating system.

You can use this method to obtain error codes only if you apply the DllImportAttribute to the method signature and set the DllImportAttribute.SetLastError field to true. The process for this varies depending upon the source language used: C# and C++ are false by default, but the Declare statement in Visual Basic is true.

public static GetLastError ( ) : Win32ErrorCode
return Win32ErrorCode

IsWow64Process() public static method

public static IsWow64Process ( SafeObjectHandle hProcess ) : bool
hProcess SafeObjectHandle
return bool

LocalAlloc() public static method

Allocates the specified number of bytes from the heap.
public static LocalAlloc ( LocalAllocFlags uFlags, int uBytes ) : void*
uFlags LocalAllocFlags /// The memory allocation attributes. The default is the value. This parameter can be one or more of the following values, except for the incompatible combinations that are specifically noted. ///
uBytes int The number of bytes to allocate. If this parameter is zero and the parameter specifies , the function returns a handle to a memory object that is marked as discarded.
return void*

LocalReAlloc() public static method

Changes the size or the attributes of a specified local memory object. The size can increase or decrease.
If LocalReAlloc fails, the original memory is not freed, and the original handle and pointer are still valid. If LocalReAlloc reallocates a fixed object, the value of the handle returned is the address of the first byte of the memory block. To access the memory, a process can simply cast the return value to a pointer.
public static LocalReAlloc ( void hMem, int uBytes, LocalReAllocFlags uFlags ) : void*
hMem void A handle to the local memory object to be reallocated. This handle is returned by either the or function.
uBytes int The new size of the memory block, in bytes. If uFlags specifies , this parameter is ignored.
uFlags LocalReAllocFlags /// The reallocation options. If is specified, the function modifies the attributes of the memory object only (the uBytes parameter is ignored.) Otherwise, the function reallocates the memory object. ///
return void*

MAKELANGID() public static method

Creates a language identifier from a primary language identifier and a sublanguage identifier.
public static MAKELANGID ( LANGID ePrimaryLanguage, LANGID eSubLanguage ) : LANGID
ePrimaryLanguage LANGID /// Primary language identifier. This identifier can be a predefined value or a value for a user-defined primary /// language. For a user-defined language, the identifier is a value in the range 0x0200 to 0x03FF. All other /// values are reserved for operating system use. For more information, see Language Identifier Constants and /// Strings. ///
eSubLanguage LANGID /// Sublanguage identifier. This parameter can be a predefined sublanguage identifier or a user-defined /// sublanguage. For a user-defined sublanguage, the identifier is a value in the range 0x20 to 0x3F. All other /// values are reserved for operating system use. For more information, see Language Identifier Constants and /// Strings. ///
return LANGID

MAKELANGID() public static method

Creates a language identifier from a primary language identifier and a sublanguage identifier.
public static MAKELANGID ( ushort usPrimaryLanguage, ushort usSubLanguage ) : LANGID
usPrimaryLanguage ushort /// Primary language identifier. This identifier can be a predefined value or a value for a user-defined primary /// language. For a user-defined language, the identifier is a value in the range 0x0200 to 0x03FF. All other /// values are reserved for operating system use. For more information, see Language Identifier Constants and /// Strings. ///
usSubLanguage ushort /// Sublanguage identifier. This parameter can be a predefined sublanguage identifier or a user-defined /// sublanguage. For a user-defined sublanguage, the identifier is a value in the range 0x20 to 0x3F. All other /// values are reserved for operating system use. For more information, see Language Identifier Constants and /// Strings. ///
return LANGID

Module32Enumerate() public static method

Retrieves information about next module encountered in a system snapshot.
Thrown if any error occurs. If is .
public static Module32Enumerate ( SafeObjectHandle hSnapshot ) : IEnumerable
hSnapshot SafeObjectHandle /// A handle to the snapshot returned from a previous call to the /// function. ///
return IEnumerable

Module32First() public static method

Retrieves information about the first module encountered in a system snapshot.
Thrown if any error occurs. If is .
public static Module32First ( SafeObjectHandle hSnapshot ) : MODULEENTRY32?
hSnapshot SafeObjectHandle /// A handle to the snapshot returned from a previous call to the /// function. ///
return MODULEENTRY32?

Module32Next() public static method

Retrieves information about the next module encountered in a system snapshot.
Thrown if any error occurs. If is .
public static Module32Next ( SafeObjectHandle hSnapshot ) : MODULEENTRY32?
hSnapshot SafeObjectHandle /// A handle to the snapshot returned from a previous call to the /// function. ///
return MODULEENTRY32?

Process32Enumerate() public static method

Retrieves information about next process encountered in a system snapshot.
Thrown if any error occurs. If is .
public static Process32Enumerate ( SafeObjectHandle hSnapshot ) : IEnumerable
hSnapshot SafeObjectHandle /// A handle to the snapshot returned from a previous call to the /// function. ///
return IEnumerable

Process32First() public static method

Retrieves information about the first process encountered in a system snapshot.
Thrown if any error occurs. If is .
public static Process32First ( SafeObjectHandle hSnapshot ) : PROCESSENTRY32?
hSnapshot SafeObjectHandle /// A handle to the snapshot returned from a previous call to the /// function. ///
return PROCESSENTRY32?

Process32Next() public static method

Retrieves information about the next process encountered in a system snapshot.
Thrown if any error occurs. If is .
public static Process32Next ( SafeObjectHandle hSnapshot ) : PROCESSENTRY32?
hSnapshot SafeObjectHandle /// A handle to the snapshot returned from a previous call to the /// function. ///
return PROCESSENTRY32?

QueryFullProcessImageName() public static method

public static QueryFullProcessImageName ( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags = QueryFullProcessImageNameFlags.None ) : string
hProcess SafeObjectHandle
dwFlags QueryFullProcessImageNameFlags
return string

ReadFile() public static method

Reads data synchronously from the specified file or input/output (I/O) device.
Thrown if the native method return false (Read failed). If is .
public static ReadFile ( SafeObjectHandle hFile, int nNumberOfBytesToRead ) : ArraySegment
hFile SafeObjectHandle /// A handle to the device (for example, a file, file stream, physical disk, volume, console buffer, /// tape drive, socket, communications resource, mailslot, or pipe). /// The hFile parameter must have been created with read access. ///
nNumberOfBytesToRead int The maximum number of bytes to be read.
return ArraySegment

ReadFile() public static method

Reads data synchronously from the specified file or input/output (I/O) device.
Thrown if the native method return false (Read failed). If is .
public static ReadFile ( SafeObjectHandle hFile, ArraySegment lpBuffer ) : int
hFile SafeObjectHandle /// A handle to the device (for example, a file, file stream, physical disk, volume, console buffer, /// tape drive, socket, communications resource, mailslot, or pipe). /// The hFile parameter must have been created with read access. ///
lpBuffer ArraySegment A buffer that receives the data read from a file or device.
return int

ReadFile() public static method

Reads data synchronously from the specified file or input/output (I/O) device.
Thrown if the native method return false (Read failed). If is .
public static ReadFile ( SafeObjectHandle hFile, void lpBuffer, int nNumberOfBytesToRead ) : int
hFile SafeObjectHandle /// A handle to the device (for example, a file, file stream, physical disk, volume, console buffer, /// tape drive, socket, communications resource, mailslot, or pipe). /// The hFile parameter must have been created with read access. ///
lpBuffer void A pointer to the buffer that receives the data read from a file or device.
nNumberOfBytesToRead int The maximum number of bytes to be read.
return int

WriteFile() public static method

Writes data synchronously to the specified file or input/output (I/O) device.
Thrown if the native method return false (Write failed). If is .
public static WriteFile ( SafeObjectHandle hFile, ArraySegment lpBuffer ) : int
hFile SafeObjectHandle /// A handle to the file or I/O device (for example, a file, file stream, physical disk, volume, console buffer, tape /// drive, socket, communications resource, mailslot, or pipe). /// /// The hFile parameter must have been created with the write access. For more information, see Generic Access /// Rights and File Security and Access Rights. /// ///
lpBuffer ArraySegment The buffer containing the data to be written to the file or device.
return int

WriteFile() public static method

Writes data synchronously to the specified file or input/output (I/O) device.
Thrown if the native method return false (Write failed). If is .
public static WriteFile ( SafeObjectHandle hFile, void lpBuffer, int nNumberOfBytesToWrite ) : int
hFile SafeObjectHandle /// A handle to the file or I/O device (for example, a file, file stream, physical disk, volume, console buffer, tape /// drive, socket, communications resource, mailslot, or pipe). /// /// The hFile parameter must have been created with the write access. For more information, see Generic Access /// Rights and File Security and Access Rights. /// ///
lpBuffer void A pointer to the buffer containing the data to be written to the file or device.
nNumberOfBytesToWrite int /// The number of bytes to be written to the file or device. /// /// A value of zero specifies a null write operation. The behavior of a null write operation depends on the /// underlying file system or communications technology. /// ///
return int

Property Details

INVALID_HANDLE_VALUE public_oe static_oe property

Constant for invalid handle value
public static IntPtr,System INVALID_HANDLE_VALUE
return System.IntPtr