Completed additional of all methods and supporting elements to Kernel32

pull/10/head
David Hall 2018-08-07 17:23:17 -06:00
parent acb6097003
commit 13e3259f8b
21 changed files with 17653 additions and 2690 deletions

1756
PInvoke/Kernel32/AppModel.cs Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,210 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// <summary>
/// <para>Initializes the head of a singly linked list.</para>
/// </summary>
/// <param name="ListHead">
/// <para>
/// A pointer to an <c>SLIST_HEADER</c> structure that represents the head of a singly linked list. This structure is for system use only.
/// </para>
/// </param>
/// <returns>
/// <para>This function does not return a value.</para>
/// </returns>
/// <remarks>
/// <para>
/// All list items must be aligned on a <c>MEMORY_ALLOCATION_ALIGNMENT</c> boundary. Unaligned items can cause unpredictable results.
/// See <c>_aligned_malloc</c>.
/// </para>
/// <para>
/// To add items to the list, use the InterlockedPushEntrySList function. To remove items from the list, use the
/// InterlockedPopEntrySList function.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Using Singly Linked Lists.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-initializeslisthead void
// InitializeSListHead( PSLIST_HEADER ListHead );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("interlockedapi.h", MSDNShortId = "4e34f947-1687-4ea9-aaa1-8d8dc11dad70")]
public static extern void InitializeSListHead(IntPtr ListHead);
/// <summary>
/// <para>Removes all items from a singly linked list. Access to the list is synchronized on a multiprocessor system.</para>
/// </summary>
/// <param name="ListHead">
/// <para>
/// Pointer to an <c>SLIST_HEADER</c> structure that represents the head of the singly linked list. This structure is for system use only.
/// </para>
/// </param>
/// <returns>
/// <para>The return value is a pointer to the items removed from the list. If the list is empty, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>
/// All list items must be aligned on a <c>MEMORY_ALLOCATION_ALIGNMENT</c> boundary; otherwise, this function will behave
/// unpredictably. See <c>_aligned_malloc</c>.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Using Singly Linked Lists.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedflushslist PSLIST_ENTRY
// InterlockedFlushSList( PSLIST_HEADER ListHead );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("interlockedapi.h", MSDNShortId = "3fde3377-8a98-4976-a350-2c173b209e8c")]
public static extern IntPtr InterlockedFlushSList(IntPtr ListHead);
/// <summary>
/// <para>Removes an item from the front of a singly linked list. Access to the list is synchronized on a multiprocessor system.</para>
/// </summary>
/// <param name="ListHead">
/// <para>Pointer to an <c>SLIST_HEADER</c> structure that represents the head of a singly linked list.</para>
/// </param>
/// <returns>
/// <para>The return value is a pointer to the item removed from the list. If the list is empty, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>
/// All list items must be aligned on a <c>MEMORY_ALLOCATION_ALIGNMENT</c> boundary; otherwise, this function will behave
/// unpredictably. See <c>_aligned_malloc</c>.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Using Singly Linked Lists.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedpopentryslist PSLIST_ENTRY
// InterlockedPopEntrySList( PSLIST_HEADER ListHead );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("interlockedapi.h", MSDNShortId = "10760fd4-5973-4ab0-991c-7a5951c798a4")]
public static extern IntPtr InterlockedPopEntrySList(IntPtr ListHead);
/// <summary>
/// <para>Inserts an item at the front of a singly linked list. Access to the list is synchronized on a multiprocessor system.</para>
/// </summary>
/// <param name="ListHead">
/// <para>Pointer to an <c>SLIST_HEADER</c> structure that represents the head of a singly linked list.</para>
/// </param>
/// <param name="ListEntry">
/// <para>Pointer to an SLIST_ENTRY structure that represents an item in a singly linked list.</para>
/// </param>
/// <returns>
/// <para>The return value is the previous first item in the list. If the list was previously empty, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>
/// All list items must be aligned on a <c>MEMORY_ALLOCATION_ALIGNMENT</c> boundary; otherwise, this function will behave
/// unpredictably. See <c>_aligned_malloc</c>.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Using Singly Linked Lists.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedpushentryslist PSLIST_ENTRY
// InterlockedPushEntrySList( PSLIST_HEADER ListHead, __drv_aliasesMem PSLIST_ENTRY ListEntry );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("interlockedapi.h", MSDNShortId = "60e3b6f7-f556-4699-be90-db7330cfb8ca")]
public static extern IntPtr InterlockedPushEntrySList(IntPtr ListHead, ref SLIST_ENTRY ListEntry);
/// <summary>
/// Inserts a singly-linked list at the front of another singly linked list. Access to the lists is synchronized on a multiprocessor system.
/// </summary>
/// <param name="ListHead">
/// Pointer to an <c>SLIST_HEADER</c> structure that represents the head of a singly linked list. The list specified by the List and
/// ListEnd parameters is inserted at the front of this list.
/// </param>
/// <param name="List">Pointer to an <c>SLIST_ENTRY</c> structure that represents the first item in the list to be inserted.</param>
/// <param name="ListEnd">Pointer to an <c>SLIST_ENTRY</c> structure that represents the last item in the list to be inserted.</param>
/// <param name="Count">The number of items in the list to be inserted.</param>
/// <returns>
/// The return value is the previous first item in the list specified by the ListHead parameter. If the list was previously empty,
/// the return value is <c>NULL</c>.
/// </returns>
// PSLIST_ENTRY FASTCALL InterlockedPushListSList( _Inout_ PSLIST_HEADER ListHead, _Inout_ PSLIST_ENTRY List, _Inout_ PSLIST_ENTRY
// ListEnd, _In_ ULONG Count); https://msdn.microsoft.com/en-us/library/windows/desktop/hh448545(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "hh448545")]
public static extern IntPtr InterlockedPushListSList(IntPtr ListHead, ref SLIST_ENTRY List, ref SLIST_ENTRY ListEnd, uint Count);
/// <summary>
/// <para>
/// Inserts a singly-linked list at the front of another singly linked list. Access to the lists is synchronized on a multiprocessor
/// system. This version of the method does not use the __fastcall calling convention.
/// </para>
/// </summary>
/// <param name="ListHead">
/// <para>
/// Pointer to an <c>SLIST_HEADER</c> structure that represents the head of a singly linked list. The list specified by the List and
/// ListEnd parameters is inserted at the front of this list.
/// </para>
/// </param>
/// <param name="List">
/// <para>Pointer to an SLIST_ENTRY structure that represents the first item in the list to be inserted.</para>
/// </param>
/// <param name="ListEnd">
/// <para>Pointer to an SLIST_ENTRY structure that represents the last item in the list to be inserted.</para>
/// </param>
/// <param name="Count">
/// <para>The number of items in the list to be inserted.</para>
/// </param>
/// <returns>
/// <para>
/// The return value is the previous first item in the list specified by the ListHead parameter. If the list was previously empty,
/// the return value is <c>NULL</c>.
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// All list items must be aligned on a <c>MEMORY_ALLOCATION_ALIGNMENT</c> boundary; otherwise, this function will behave
/// unpredictably. See <c>_aligned_malloc</c>.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedpushlistslistex PSLIST_ENTRY
// InterlockedPushListSListEx( PSLIST_HEADER ListHead, PSLIST_ENTRY List, PSLIST_ENTRY ListEnd, ULONG Count );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("interlockedapi.h", MSDNShortId = "f4f334c6-fda8-4c5f-9177-b672c8aed6b3")]
public static extern IntPtr InterlockedPushListSListEx(IntPtr ListHead, ref SLIST_ENTRY List, ref SLIST_ENTRY ListEnd, uint Count);
/// <summary>
/// <para>Retrieves the number of entries in the specified singly linked list.</para>
/// </summary>
/// <param name="ListHead">
/// <para>
/// A pointer to an <c>SLIST_HEADER</c> structure that represents the head of a singly linked list. This structure is for system use only.
/// </para>
/// <para>The list must be previously initialized with the InitializeSListHead function.</para>
/// </param>
/// <returns>
/// <para>The function returns the number of entries in the list, up to a maximum value of 65535.</para>
/// </returns>
/// <remarks>
/// <para>
/// The system does not limit the number of entries in a singly linked list. However, the return value of <c>QueryDepthSList</c> is
/// truncated to 16 bits, so the maximum value it can return is 65535. If the specified singly linked list contains more than 65535
/// entries, <c>QueryDepthSList</c> returns the number of entries in the list modulo 65535. For example, if the specified list
/// contains 65536 entries, <c>QueryDepthSList</c> returns zero.
/// </para>
/// <para>
/// The return value of <c>QueryDepthSList</c> should not be relied upon in multithreaded applications because the item count can be
/// changed at any time by another thread.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-querydepthslist USHORT QueryDepthSList(
// PSLIST_HEADER ListHead );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("interlockedapi.h", MSDNShortId = "3f9b4481-647f-457f-bdfb-62e6ae4198e5")]
public static extern ushort QueryDepthSList(IntPtr ListHead);
/// <summary>An <c>SLIST_ENTRY</c> structure describes an entry in a sequenced singly linked list.</summary>
// typedef struct _SLIST_ENTRY { struct _SLIST_ENTRY *Next;} SLIST_ENTRY, *PSLIST_ENTRY; https://msdn.microsoft.com/en-us/library/windows/hardware/ff563805(v=vs.85).aspx
[PInvokeData("Wdm.h", MSDNShortId = "ff563805")]
[StructLayout(LayoutKind.Sequential)]
public struct SLIST_ENTRY
{
/// <summary>Pointer to the next entry in the list, or <c>NULL</c> if there is no next entry in the list.</summary>
public IntPtr Next;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2840,22 +2840,23 @@ namespace Vanara.PInvoke
public static extern SizeT VirtualQueryEx([In] IntPtr hProcess, [In] IntPtr lpAddress, IntPtr lpBuffer, SizeT dwLength); public static extern SizeT VirtualQueryEx([In] IntPtr hProcess, [In] IntPtr lpAddress, IntPtr lpBuffer, SizeT dwLength);
/// <summary> /// <summary>
/// Unlocks a specified range of pages in the virtual address space of a process, enabling the system to swap the pages out to the paging file if necessary. /// Unlocks a specified range of pages in the virtual address space of a process, enabling the system to swap the pages out to the
/// paging file if necessary.
/// </summary> /// </summary>
/// <param name="lpAddress">A pointer to the base address of the region of pages to be unlocked.</param> /// <param name="lpAddress">A pointer to the base address of the region of pages to be unlocked.</param>
/// <param name="dwSize"> /// <param name="dwSize">
/// The size of the region being unlocked, in bytes. The region of affected pages includes all pages containing one or more bytes in the range from the /// The size of the region being unlocked, in bytes. The region of affected pages includes all pages containing one or more bytes in
/// lpAddress parameter to . This means that a 2-byte range straddling a page boundary causes both pages to be unlocked. /// the range from the lpAddress parameter to . This means that a 2-byte range straddling a page boundary causes both pages to be unlocked.
/// </param> /// </param>
/// <returns> /// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para> /// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call <c>GetLastError</c>.</para> /// <para>If the function fails, the return value is zero. To get extended error information, call <c>GetLastError</c>.</para>
/// </returns> /// </returns>
// BOOL WINAPI VirtualUnlock( _In_ LPVOID lpAddress, _In_ SIZE_T dwSize); // BOOL WINAPI VirtualUnlock( _In_ LPVOID lpAddress, _In_ SIZE_T dwSize); https://msdn.microsoft.com/en-us/library/windows/desktop/aa366910(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "aa366910")] [PInvokeData("WinBase.h", MSDNShortId = "aa366910")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool VirtualUnlock([In] IntPtr lpAddress, SizeT dwSize); public static extern bool VirtualUnlock(IntPtr lpAddress, SizeT dwSize);
/// <summary>Writes data to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails.</summary> /// <summary>Writes data to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails.</summary>
/// <param name="hProcess"> /// <param name="hProcess">

File diff suppressed because it is too large Load Diff

View File

@ -1546,6 +1546,26 @@ namespace Vanara.PInvoke
[PInvokeData("WinBase.h", MSDNShortId = "ms683180")] [PInvokeData("WinBase.h", MSDNShortId = "ms683180")]
public static extern uint GetCurrentProcessId(); public static extern uint GetCurrentProcessId();
/// <summary>
/// <para>Retrieves the number of the processor the current thread was running on during the call to this function.</para>
/// </summary>
/// <returns>
/// <para>The function returns the current processor number.</para>
/// </returns>
/// <remarks>
/// <para>This function is used to provide information for estimating process performance.</para>
/// <para>
/// On systems with more than 64 logical processors, the <c>GetCurrentProcessorNumber</c> function returns the processor number
/// within the processor group to which the logical processor is assigned. Use the GetCurrentProcessorNumberEx function to retrieve
/// the processor group and number of the current processor.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocessornumber
// DWORD GetCurrentProcessorNumber( );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("processthreadsapi.h", MSDNShortId = "1f2bebc7-a548-409a-ab74-78a4b55c8fa7")]
public static extern uint GetCurrentProcessorNumber();
/// <summary>Retrieves the processor group and number of the logical processor in which the calling thread is running.</summary> /// <summary>Retrieves the processor group and number of the logical processor in which the calling thread is running.</summary>
/// <param name="ProcNumber"> /// <param name="ProcNumber">
/// A pointer to a <c>PROCESSOR_NUMBER</c> structure that receives the processor group to which the logical processor is assigned and the number of the /// A pointer to a <c>PROCESSOR_NUMBER</c> structure that receives the processor group to which the logical processor is assigned and the number of the

1398
PInvoke/Kernel32/PsApi.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,117 +1,243 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using Vanara.InteropServices;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
namespace Vanara.PInvoke namespace Vanara.PInvoke
{ {
public static partial class Kernel32 public static partial class Kernel32
{ {
/* AccessCheck /// <summary>
AccessCheckAndAuditAlarmW /// <para>
AccessCheckByType /// The <c>AddResourceAttributeAce</c> function adds a SYSTEM_RESOURCE_ATTRIBUTE_ACE access control entry (ACE) to the end of a
AccessCheckByTypeAndAuditAlarmW /// system access control list (SACL). A <c>SYSTEM_RESOURCE_ATTRIBUTE_ACE</c> structure specifies an attribute name and a
AccessCheckByTypeResultList /// value-ordered list of elements that is associated with a resource and potentially used during access checks. The set of standard
AccessCheckByTypeResultListAndAuditAlarmByHandleW /// access rights are defined in the Standard Access Rights topic.
AccessCheckByTypeResultListAndAuditAlarmW /// </para>
AddAccessAllowedAce /// </summary>
AddAccessAllowedAceEx /// <param name="pAcl">
AddAccessAllowedObjectAce /// <para>
AddAccessDeniedAce /// A pointer to an access control list (ACL). This function adds an ACE to this ACL. The value of this parameter cannot be
AddAccessDeniedAceEx /// <c>NULL</c>. The ACE is in the form of a SYSTEM_RESOURCE_ATTRIBUTE_ACE structure.
AddAccessDeniedObjectAce /// </para>
AddAce /// </param>
AddAuditAccessAce /// <param name="dwAceRevision">
AddAuditAccessAceEx /// <para>
AddAuditAccessObjectAce /// Specifies the revision level of the ACL being modified. This value can be ACL_REVISION or ACL_REVISION_DS. Use ACL_REVISION_DS if
AddMandatoryAce /// the ACL contains object-specific ACEs.
AddResourceAttributeAce /// </para>
AddScopedPolicyIDAce /// </param>
AdjustTokenGroups /// <param name="AceFlags">
AdjustTokenPrivileges /// <para>
AllocateAndInitializeSid /// A set of bit flags that control ACE inheritance. The function sets these flags in the <c>AceFlags</c> member of the ACE_HEADER
AllocateLocallyUniqueId /// structure of the new ACE.
AreAllAccessesGranted /// </para>
AreAnyAccessesGranted /// <para>
CheckTokenCapability /// For consistency with the Windows 8 Advanced File Permissions UI, applications should specify the CONTAINER_INHERIT_ACE and
CheckTokenMembership /// OBJECT_INHERIT_ACE flags in the parameter.
CheckTokenMembershipEx /// </para>
ConvertToAutoInheritPrivateObjectSecurity /// <para>This parameter can be a combination of the following values.</para>
CopySid /// <list type="table">
CreatePrivateObjectSecurity /// <listheader>
CreatePrivateObjectSecurityEx /// <term>Value</term>
CreatePrivateObjectSecurityWithMultipleInheritance /// <term>Meaning</term>
CreateRestrictedToken /// </listheader>
CreateWellKnownSid /// <item>
CveEventWrite /// <term>CONTAINER_INHERIT_ACE 2 (0x2)</term>
DeleteAce /// <term>The ACE is inherited by the container objects.</term>
DeriveCapabilitySidsFromName /// </item>
DestroyPrivateObjectSecurity /// <item>
DuplicateToken /// <term>INHERIT_ONLY_ACE 8 (0x8)</term>
DuplicateTokenEx /// <term>The ACE does not apply to the object the ACE is assigned to, but it can be inherited by child objects.</term>
EqualDomainSid /// </item>
EqualPrefixSid /// <item>
EqualSid /// <term>INHERITED_ACE 16 (0x10)</term>
FindFirstFreeAce /// <term>
FreeSid /// Indicates an inherited ACE. This flag allows operations that change the security on a tree of objects to modify inherited ACEs
GetAce /// while not changing ACEs that were directly applied to the object.
GetAclInformation /// </term>
GetAppContainerAce /// </item>
GetCachedSigningLevel /// <item>
GetFileSecurityW /// <term>NO_PROPAGATE_INHERIT_ACE 4 (0x4)</term>
GetKernelObjectSecurity /// <term>The OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE bits are not propagated to an inherited ACE.</term>
GetLengthSid /// </item>
GetPrivateObjectSecurity /// <item>
GetSecurityDescriptorControl /// <term>OBJECT_INHERIT_ACE 1 (0x1)</term>
GetSecurityDescriptorDacl /// <term>The ACE is inherited by non-container objects.</term>
GetSecurityDescriptorGroup /// </item>
GetSecurityDescriptorLength /// </list>
GetSecurityDescriptorOwner /// </param>
GetSecurityDescriptorOwner /// <param name="AccessMask">
GetSecurityDescriptorSacl /// <para>Must be zero for Windows 8 and Windows Server 2012.</para>
GetSidIdentifierAuthority /// </param>
GetSidLengthRequired /// <param name="pSid">
GetSidSubAuthority /// <para>Must be the Everyone SID (S-1-1-0) for Windows 8 and Windows Server 2012.</para>
GetSidSubAuthorityCount /// </param>
GetTokenInformation /// <param name="pAttributeInfo">
GetWindowsAccountDomainSid /// <para>Specifies the attribute information that will be appended after the SID in the ACE.</para>
ImpersonateAnonymousToken /// </param>
ImpersonateLoggedOnUser /// <param name="pReturnLength">
ImpersonateSelf /// <para>
InitializeAcl /// The size, in bytes, of the actual ACL buffer used. If the buffer specified by the parameter is not big enough, the value of this
InitializeSecurityDescriptor /// parameter is the total size required for the ACL buffer.
InitializeSid /// </para>
IsTokenRestricted /// </param>
IsValidAcl /// <returns>
IsValidSecurityDescriptor /// <para>If the function succeeds, it returns <c>TRUE</c>.</para>
IsValidSid /// <para>If the function fails, it returns <c>FALSE</c>. To get extended error information, call GetLastError.</para>
IsWellKnownSid /// </returns>
MakeAbsoluteSD // https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-addresourceattributeace BOOL
MakeSelfRelativeSD // AddResourceAttributeAce( PACL pAcl, DWORD dwAceRevision, DWORD AceFlags, DWORD AccessMask, PSID pSid,
MapGenericMask // PCLAIM_SECURITY_ATTRIBUTES_INFORMATION pAttributeInfo, PDWORD pReturnLength );
ObjectCloseAuditAlarmW [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
ObjectDeleteAuditAlarmW [PInvokeData("securitybaseapi.h", MSDNShortId = "AA2064E4-6F76-4D7B-8540-D55A91168825")]
ObjectOpenAuditAlarmW [return: MarshalAs(UnmanagedType.Bool)]
ObjectPrivilegeAuditAlarmW public static extern bool AddResourceAttributeAce(PACL pAcl, uint dwAceRevision, uint AceFlags, uint AccessMask, PSID pSid, ref CLAIM_SECURITY_ATTRIBUTES_INFORMATION pAttributeInfo, ref uint pReturnLength);
PrivilegeCheck
PrivilegedServiceAuditAlarmW /// <summary>
QuerySecurityAccessMask /// <para>
RevertToSelf /// The <c>AddScopedPolicyIDAce</c> function adds a SYSTEM_SCOPED_POLICY_ID_ACE access control entry (ACE) to the end of a system
SetAclInformation /// access control list (SACL). A <c>SYSTEM_SCOPED_POLICY_ID_ACE</c> structure specifies a central access policy (CAP) to be
SetCachedSigningLevel /// associated with the resource and can be used during access checks. The set of standard access rights are defined in the Standard
SetFileSecurityW /// Access Rights topic.
SetKernelObjectSecurity /// </para>
SetPrivateObjectSecurity /// </summary>
SetPrivateObjectSecurityEx /// <param name="pAcl">
SetSecurityAccessMask /// <para>
SetSecurityDescriptorControl /// A pointer to an access control list (ACL). This function adds an ACE to this ACL. The value of this parameter cannot be <c>NULL</c>.
SetSecurityDescriptorDacl /// </para>
SetSecurityDescriptorGroup /// </param>
SetSecurityDescriptorOwner /// <param name="dwAceRevision">
SetSecurityDescriptorRMControl /// <para>
SetSecurityDescriptorSacl /// Specifies the revision level of the ACL being modified. This value can be ACL_REVISION or ACL_REVISION_DS. Use ACL_REVISION_DS if
SetTokenInformation /// the ACL contains object-specific ACEs.
*/ /// </para>
/// </param>
/// <param name="AceFlags">
/// <para>
/// A set of bit flags that control ACE inheritance. The function sets these flags in the <c>AceFlags</c> member of the ACE_HEADER
/// structure of the new ACE.
/// </para>
/// <para>
/// For consistency with the Windows 8 Advanced File Permissions UI, applications should specify the CONTAINER_INHERIT_ACE and
/// OBJECT_INHERIT_ACE flags in the parameter.
/// </para>
/// <para>This parameter can be a combination of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>CONTAINER_INHERIT_ACE 2 (0x2)</term>
/// <term>The ACE is inherited by the container objects.</term>
/// </item>
/// <item>
/// <term>INHERIT_ONLY_ACE 8 (0x8)</term>
/// <term>The ACE does not apply to the object the ACE is assigned to, but it can be inherited by child objects.</term>
/// </item>
/// <item>
/// <term>INHERITED_ACE 16 (0x10)</term>
/// <term>
/// Indicates an inherited ACE. This flag allows operations that change the security on a tree of objects to modify inherited ACEs
/// while not changing ACEs that were directly applied to the object.
/// </term>
/// </item>
/// <item>
/// <term>NO_PROPAGATE_INHERIT_ACE 4 (0x4)</term>
/// <term>The OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE bits are not propagated to an inherited ACE.</term>
/// </item>
/// <item>
/// <term>OBJECT_INHERIT_ACE 1 (0x1)</term>
/// <term>The ACE is inherited by non-container objects.</term>
/// </item>
/// </list>
/// </param>
/// <param name="AccessMask">
/// <para>Must be zero for Windows 8 and Windows Server 2012.</para>
/// </param>
/// <param name="pSid">
/// <para>A pointer to the SID (S-1-17-*) that identifies the Central Access Policy to be associated with the resource.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, it returns <c>TRUE</c>.</para>
/// <para>If the function fails, it returns <c>FALSE</c>. To get extended error information, call GetLastError.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-addscopedpolicyidace BOOL
// AddScopedPolicyIDAce( PACL pAcl, DWORD dwAceRevision, DWORD AceFlags, DWORD AccessMask, PSID pSid );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("securitybaseapi.h", MSDNShortId = "30AA5730-566C-4B02-A904-5A38237EE8E3")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddScopedPolicyIDAce(PACL pAcl, uint dwAceRevision, uint AceFlags, uint AccessMask, PSID pSid);
/// <summary>
/// <para>The <c>CheckTokenCapability</c> function checks the capabilities of a given token.</para>
/// </summary>
/// <param name="TokenHandle">
/// <para>
/// A handle to an access token. The handle must have TOKEN_QUERY access to the token. The token must be an impersonation token.
/// </para>
/// <para>
/// If is <c>NULL</c>, <c>CheckTokenCapability</c> uses the impersonation token of the calling thread. If the thread is not
/// impersonating, the function duplicates the thread's primary token to create an impersonation token.
/// </para>
/// </param>
/// <param name="CapabilitySidToCheck">
/// <para>
/// A pointer to a capability SID structure. The <c>CheckTokenCapability</c> function checks the capabilities of this access token.
/// </para>
/// </param>
/// <param name="HasCapability">
/// <para>
/// Receives the results of the check. If the access token has the capability, it returns <c>TRUE</c>, otherwise, it returns <c>FALSE</c>.
/// </para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-checktokencapability BOOL
// CheckTokenCapability( HANDLE TokenHandle, PSID CapabilitySidToCheck, PBOOL HasCapability );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("securitybaseapi.h", MSDNShortId = "436A5110-B79E-4E64-92E8-1C9E713D0948")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CheckTokenCapability(IntPtr TokenHandle, PSID CapabilitySidToCheck, [MarshalAs(UnmanagedType.Bool)] out bool HasCapability);
/// <summary>
/// <para>
/// This function constructs two arrays of SIDs out of a capability name. One is an array group SID with NT Authority, and the other
/// is an array of capability SIDs with AppAuthority.
/// </para>
/// </summary>
/// <param name="CapName">
/// <para>Name of the capability in string form.</para>
/// </param>
/// <param name="CapabilityGroupSids">
/// <para>The GroupSids with NTAuthority.</para>
/// </param>
/// <param name="CapabilityGroupSidCount">
/// <para>The count of GroupSids in the array.</para>
/// </param>
/// <param name="CapabilitySids">
/// <para>CapabilitySids with AppAuthority.</para>
/// </param>
/// <param name="CapabilitySidCount">
/// <para>The count of CapabilitySid with AppAuthority.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, it returns <c>TRUE</c>.</para>
/// <para>If the function fails, it returns <c>FALSE</c>. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// The caller is expected to free the individual SIDs returned in each array by calling LocalFree. as well as memory allocated for
/// the array itself.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-derivecapabilitysidsfromname BOOL
// DeriveCapabilitySidsFromName( LPCWSTR CapName, PSID **CapabilityGroupSids, DWORD *CapabilityGroupSidCount, PSID **CapabilitySids,
// DWORD *CapabilitySidCount );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("securitybaseapi.h", MSDNShortId = "1A911FCC-6D11-4185-B532-20FE6C7C4B0B")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeriveCapabilitySidsFromName([MarshalAs(UnmanagedType.LPWStr)] string CapName, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] IntPtr[] CapabilityGroupSids, ref uint CapabilityGroupSidCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] IntPtr[] CapabilitySids, ref uint CapabilitySidCount);
} }
} }

View File

@ -969,7 +969,7 @@ namespace Vanara.PInvoke
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683560(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683560(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms683560")] [PInvokeData("WinBase.h", MSDNShortId = "ms683560")]
public static extern int InterlockedCompareExchange(ref int Destination, int Exchange, int Comperand); public static extern int InterlockedCompareExchange(ref int Destination, int Exchange, int Comparand);
/// <summary> /// <summary>
/// <para>Decrements (decreases by one) the value of the specified 32-bit variable as an atomic operation.</para> /// <para>Decrements (decreases by one) the value of the specified 32-bit variable as an atomic operation.</para>
@ -980,7 +980,7 @@ namespace Vanara.PInvoke
// LONG __cdecl InterlockedDecrement( _Inout_ LONG volatile *Addend); https://msdn.microsoft.com/en-us/library/windows/desktop/ms683580(v=vs.85).aspx // LONG __cdecl InterlockedDecrement( _Inout_ LONG volatile *Addend); https://msdn.microsoft.com/en-us/library/windows/desktop/ms683580(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms683580")] [PInvokeData("WinBase.h", MSDNShortId = "ms683580")]
public static extern int InterlockedDecrement(ref int lpAddend); public static extern int InterlockedDecrement(ref int Addend);
/// <summary> /// <summary>
/// <para>Sets a 32-bit variable to the specified value as an atomic operation.</para> /// <para>Sets a 32-bit variable to the specified value as an atomic operation.</para>
@ -1017,7 +1017,7 @@ namespace Vanara.PInvoke
// LONG __cdecl InterlockedIncrement( _Inout_ LONG volatile *Addend); https://msdn.microsoft.com/en-us/library/windows/desktop/ms683614(v=vs.85).aspx // LONG __cdecl InterlockedIncrement( _Inout_ LONG volatile *Addend); https://msdn.microsoft.com/en-us/library/windows/desktop/ms683614(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms683614")] [PInvokeData("WinBase.h", MSDNShortId = "ms683614")]
public static extern int InterlockedIncrement(ref int lpAddend); public static extern int InterlockedIncrement(ref int Addend);
/// <summary>Releases ownership of the specified critical section object.</summary> /// <summary>Releases ownership of the specified critical section object.</summary>
/// <param name="lpCriticalSection">A pointer to the critical section object.</param> /// <param name="lpCriticalSection">A pointer to the critical section object.</param>
@ -1300,7 +1300,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms686289")] [PInvokeData("WinBase.h", MSDNShortId = "ms686289")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWaitableTimer([In] IntPtr hTimer, [In] ref FILETIME lpDueTime, int lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, public static extern bool SetWaitableTimer([In] IntPtr hTimer, [In] ref FILETIME pDueTime, int lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine,
[In] IntPtr lpArgToCompletionRoutine, [MarshalAs(UnmanagedType.Bool)] bool fResume); [In] IntPtr lpArgToCompletionRoutine, [MarshalAs(UnmanagedType.Bool)] bool fResume);
/// <summary> /// <summary>

View File

@ -160,8 +160,12 @@ namespace Vanara.PInvoke
public static extern bool SetDynamicTimeZoneInformation(ref DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation); public static extern bool SetDynamicTimeZoneInformation(ref DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation);
/// <summary> /// <summary>
/// <para>Sets the current time zone settings. These settings control translations from Coordinated Universal Time (UTC) to local time.</para> /// <para>
/// <para>To support boundaries for daylight saving time that change from year to year, use the <c>SetDynamicTimeZoneInformation</c> function.</para> /// Sets the current time zone settings. These settings control translations from Coordinated Universal Time (UTC) to local time.
/// </para>
/// <para>
/// To support boundaries for daylight saving time that change from year to year, use the <c>SetDynamicTimeZoneInformation</c> function.
/// </para>
/// </summary> /// </summary>
/// <param name="lpTimeZoneInformation">A pointer to a <c>TIME_ZONE_INFORMATION</c> structure that contains the new settings.</param> /// <param name="lpTimeZoneInformation">A pointer to a <c>TIME_ZONE_INFORMATION</c> structure that contains the new settings.</param>
/// <returns> /// <returns>
@ -172,7 +176,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Winbase.h", MSDNShortId = "ms724944")] [PInvokeData("Winbase.h", MSDNShortId = "ms724944")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetTimeZoneInformation([In] ref TIME_ZONE_INFORMATION lpTimeZoneInformation); public static extern bool SetTimeZoneInformation(ref TIME_ZONE_INFORMATION lpTimeZoneInformation);
/// <summary>Converts a system time to file time format. System time is based on Coordinated Universal Time (UTC).</summary> /// <summary>Converts a system time to file time format. System time is based on Coordinated Universal Time (UTC).</summary>
/// <param name="lpSystemTime"> /// <param name="lpSystemTime">

View File

@ -0,0 +1,851 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// <summary>Used by HEAPENTRY32</summary>
[PInvokeData("tlhelp32.h", MSDNShortId = "c5f1dc66-d44f-4491-b0b7-961b163d0f1f")]
[Flags]
public enum HEAPENTRY32_FLAGS
{
/// <summary>The memory block has a fixed (unmovable) location.</summary>
LF32_FIXED = 0x00000001,
/// <summary>The memory block is not used.</summary>
LF32_FREE = 0x00000002,
/// <summary>The memory block location can be moved.</summary>
LF32_MOVEABLE = 0x00000004,
}
/// <summary>Used by HEAPLIST32</summary>
[PInvokeData("tlhelp32.h", MSDNShortId = "61e01d23-9f15-44c5-9f6d-45df4809ccad")]
[Flags]
public enum HEAPLIST32_FLAGS
{
/// <summary>Process's default heap</summary>
HF32_DEFAULT = 1,
/// <summary>Process's shared heap</summary>
HF32_SHARED = 2
}
/// <summary>Flags used by <see cref="CreateToolhelp32Snapshot"/>.</summary>
[PInvokeData("tlhelp32.h", MSDNShortId = "df643c25-7558-424c-b187-b3f86ba51358")]
public enum TH32CS : uint
{
/// <summary>Indicates that the snapshot handle is to be inheritable.</summary>
TH32CS_INHERIT = 0x80000000,
/// <summary>Includes all heaps of the process specified in th32ProcessID in the snapshot. To enumerate the heaps, see Heap32ListFirst.</summary>
TH32CS_SNAPHEAPLIST = 0x00000001,
/// <summary>
/// Includes all modules of the process specified in th32ProcessID in the snapshot. To enumerate the modules, see Module32First.
/// If the function fails with ERROR_BAD_LENGTH, retry the function until it succeeds.
/// <para>
/// 64-bit Windows: Using this flag in a 32-bit process includes the 32-bit modules of the process specified in th32ProcessID,
/// while using it in a 64-bit process includes the 64-bit modules. To include the 32-bit modules of the process specified in
/// th32ProcessID from a 64-bit process, use the TH32CS_SNAPMODULE32 flag.
/// </para>
/// </summary>
TH32CS_SNAPMODULE = 0x00000008,
/// <summary>
/// Includes all 32-bit modules of the process specified in th32ProcessID in the snapshot when called from a 64-bit process. This
/// flag can be combined with TH32CS_SNAPMODULE or TH32CS_SNAPALL. If the function fails with ERROR_BAD_LENGTH, retry the
/// function until it succeeds.
/// </summary>
TH32CS_SNAPMODULE32 = 0x00000010,
/// <summary>Includes all processes in the system in the snapshot. To enumerate the processes, see Process32First.</summary>
TH32CS_SNAPPROCESS = 0x00000002,
/// <summary>
/// Includes all threads in the system in the snapshot. To enumerate the threads, see Thread32First.
/// <para>
/// To identify the threads that belong to a specific process, compare its process identifier to the th32OwnerProcessID member of
/// the THREADENTRY32 structure when enumerating the threads.
/// </para>
/// </summary>
TH32CS_SNAPTHREAD = 0x00000004,
/// <summary>
/// Includes all processes and threads in the system, plus the heaps and modules of the process specified in th32ProcessID.
/// Equivalent to specifying the TH32CS_SNAPHEAPLIST, TH32CS_SNAPMODULE, TH32CS_SNAPPROCESS, and TH32CS_SNAPTHREAD values
/// combined using an OR operation ('|').
/// </summary>
TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE),
}
/// <summary>
/// <para>Takes a snapshot of the specified processes, as well as the heaps, modules, and threads used by these processes.</para>
/// </summary>
/// <param name="dwFlags">
/// <para>The portions of the system to be included in the snapshot. This parameter can be one or more of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>TH32CS_INHERIT 0x80000000</term>
/// <term>Indicates that the snapshot handle is to be inheritable.</term>
/// </item>
/// <item>
/// <term>TH32CS_SNAPALL</term>
/// <term>
/// Includes all processes and threads in the system, plus the heaps and modules of the process specified in . Equivalent to
/// specifying the TH32CS_SNAPHEAPLIST, TH32CS_SNAPMODULE, TH32CS_SNAPPROCESS, and TH32CS_SNAPTHREAD values combined using an OR
/// operation ('|').
/// </term>
/// </item>
/// <item>
/// <term>TH32CS_SNAPHEAPLIST 0x00000001</term>
/// <term>Includes all heaps of the process specified in in the snapshot. To enumerate the heaps, see Heap32ListFirst.</term>
/// </item>
/// <item>
/// <term>TH32CS_SNAPMODULE 0x00000008</term>
/// <term>
/// Includes all modules of the process specified in in the snapshot. To enumerate the modules, see Module32First. If the function
/// fails with ERROR_BAD_LENGTH, retry the function until it succeeds. 64-bit Windows: Using this flag in a 32-bit process includes
/// the 32-bit modules of the process specified in , while using it in a 64-bit process includes the 64-bit modules. To include the
/// 32-bit modules of the process specified in from a 64-bit process, use the TH32CS_SNAPMODULE32 flag.
/// </term>
/// </item>
/// <item>
/// <term>TH32CS_SNAPMODULE32 0x00000010</term>
/// <term>
/// Includes all 32-bit modules of the process specified in in the snapshot when called from a 64-bit process. This flag can be
/// combined with TH32CS_SNAPMODULE or TH32CS_SNAPALL. If the function fails with ERROR_BAD_LENGTH, retry the function until it succeeds.
/// </term>
/// </item>
/// <item>
/// <term>TH32CS_SNAPPROCESS 0x00000002</term>
/// <term>Includes all processes in the system in the snapshot. To enumerate the processes, see Process32First.</term>
/// </item>
/// <item>
/// <term>TH32CS_SNAPTHREAD 0x00000004</term>
/// <term>
/// Includes all threads in the system in the snapshot. To enumerate the threads, see Thread32First. To identify the threads that
/// belong to a specific process, compare its process identifier to the th32OwnerProcessID member of the THREADENTRY32 structure when
/// enumerating the threads.
/// </term>
/// </item>
/// </list>
/// </param>
/// <param name="th32ProcessID">
/// <para>
/// The process identifier of the process to be included in the snapshot. This parameter can be zero to indicate the current process.
/// This parameter is used when the <c>TH32CS_SNAPHEAPLIST</c>, <c>TH32CS_SNAPMODULE</c>, <c>TH32CS_SNAPMODULE32</c>, or
/// <c>TH32CS_SNAPALL</c> value is specified. Otherwise, it is ignored and all processes are included in the snapshot.
/// </para>
/// <para>
/// If the specified process is the Idle process or one of the CSRSS processes, this function fails and the last error code is
/// <c>ERROR_ACCESS_DENIED</c> because their access restrictions prevent user-level code from opening them.
/// </para>
/// <para>
/// If the specified process is a 64-bit process and the caller is a 32-bit process, this function fails and the last error code is
/// <c>ERROR_PARTIAL_COPY</c> (299).
/// </para>
/// </param>
/// <returns>
/// <para>If the function succeeds, it returns an open handle to the specified snapshot.</para>
/// <para>
/// If the function fails, it returns <c>INVALID_HANDLE_VALUE</c>. To get extended error information, call GetLastError. Possible
/// error codes include <c>ERROR_BAD_LENGTH</c>.
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// The snapshot taken by this function is examined by the other tool help functions to provide their results. Access to the snapshot
/// is read only. The snapshot handle acts as an object handle and is subject to the same rules regarding which processes and threads
/// it is valid in.
/// </para>
/// <para>
/// To enumerate the heap or module states for all processes, specify <c>TH32CS_SNAPALL</c> and set to zero. Then, for each
/// additional process in the snapshot, call <c>CreateToolhelp32Snapshot</c> again, specifying its process identifier and the
/// <c>TH32CS_SNAPHEAPLIST</c> or <c>TH32_SNAPMODULE</c> value.
/// </para>
/// <para>
/// When taking snapshots that include heaps and modules for a process other than the current process, the
/// <c>CreateToolhelp32Snapshot</c> function can fail or return incorrect information for a variety of reasons. For example, if the
/// loader data table in the target process is corrupted or not initialized, or if the module list changes during the function call
/// as a result of DLLs being loaded or unloaded, the function might fail with <c>ERROR_BAD_LENGTH</c> or other error code. Ensure
/// that the target process was not started in a suspended state, and try calling the function again. If the function fails with
/// <c>ERROR_BAD_LENGTH</c> when called with <c>TH32CS_SNAPMODULE</c> or <c>TH32CS_SNAPMODULE32</c>, call the function again until it succeeds.
/// </para>
/// <para>
/// The <c>TH32CS_SNAPMODULE</c> and <c>TH32CS_SNAPMODULE32</c> flags do not retrieve handles for modules that were loaded with the
/// <c>LOAD_LIBRARY_AS_DATAFILE</c> or similar flags. For more information, see LoadLibraryEx.
/// </para>
/// <para>To destroy the snapshot, use the CloseHandle function.</para>
/// <para>
/// Note that you can use the QueryFullProcessImageName function to retrieve the full name of an executable image for both 32- and
/// 64-bit processes from a 32-bit process.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Taking a Snapshot and Viewing Processes.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot HANDLE
// CreateToolhelp32Snapshot( DWORD dwFlags, DWORD th32ProcessID );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "df643c25-7558-424c-b187-b3f86ba51358")]
public static extern IntPtr CreateToolhelp32Snapshot(TH32CS dwFlags, uint th32ProcessID);
/// <summary>
/// <para>Retrieves information about the first block of a heap that has been allocated by a process.</para>
/// </summary>
/// <param name="lphe">
/// <para>A pointer to a HEAPENTRY32 structure.</para>
/// </param>
/// <param name="th32ProcessID">
/// <para>The identifier of the process context that owns the heap.</para>
/// </param>
/// <param name="th32HeapID">
/// <para>The identifier of the heap to be enumerated.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if information for the first heap block has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if the heap is invalid or empty.
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// The calling application must set the <c>dwSize</c> member of HEAPENTRY32 to the size, in bytes, of the structure.
/// <c>Heap32First</c> changes <c>dwSize</c> to the number of bytes written to the structure. This will never be greater than the
/// initial value of <c>dwSize</c>, but it may be smaller. If the value is smaller, do not rely on the values of any members whose
/// offsets are greater than this value.
/// </para>
/// <para>To access subsequent blocks of the same heap, use the Heap32Next function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Heap List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-heap32first BOOL Heap32First( LPHEAPENTRY32 lphe, DWORD
// th32ProcessID, ULONG_PTR th32HeapID );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "79d01e3a-b11b-46b5-99d0-b445000288a7")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Heap32First(ref HEAPENTRY32 lphe, uint th32ProcessID, UIntPtr th32HeapID);
/// <summary>
/// <para>Retrieves information about the first heap that has been allocated by a specified process.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lphl">
/// <para>A pointer to a HEAPLIST32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the first entry of the heap list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function when no heap list exists or the snapshot does not
/// contain heap list information.
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// The calling application must set the <c>dwSize</c> member of HEAPLIST32 to the size, in bytes, of the structure.
/// <c>Heap32ListFirst</c> changes <c>dwSize</c> to the number of bytes written to the structure. This will never be greater than the
/// initial value of <c>dwSize</c>, but it may be smaller. If the value is smaller, do not rely on the values of any members whose
/// offsets are greater than this value.
/// </para>
/// <para>To retrieve information about other heaps in the heap list, use the Heap32ListNext function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Heap List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-heap32listfirst BOOL Heap32ListFirst( HANDLE hSnapshot,
// LPHEAPLIST32 lphl );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "b9a2992b-0dc1-41c3-aa23-796def674831")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Heap32ListFirst(IntPtr hSnapshot, ref HEAPLIST32 lphl);
/// <summary>
/// <para>Retrieves information about the next heap that has been allocated by a process.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lphl">
/// <para>A pointer to a HEAPLIST32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the next entry of the heap list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function when no more entries in the heap list exist.
/// </para>
/// </returns>
/// <remarks>
/// <para>To retrieve information about the first heap in a heap list, use the Heap32ListFirst function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Heap List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-heap32listnext BOOL Heap32ListNext( HANDLE hSnapshot,
// LPHEAPLIST32 lphl );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "bb4d573c-a82f-48ac-be22-440d6a1d0c9c")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Heap32ListNext(IntPtr hSnapshot, ref HEAPLIST32 lphl);
/// <summary>
/// <para>Retrieves information about the next block of a heap that has been allocated by a process.</para>
/// </summary>
/// <param name="lphe">
/// <para>A pointer to a HEAPENTRY32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if information about the next block in the heap has been copied to the buffer or <c>FALSE</c> otherwise. The
/// GetLastError function returns <c>ERROR_NO_MORE_FILES</c> when no more objects in the heap exist and <c>ERROR_INVALID_DATA</c> if
/// the heap appears to be corrupt or is modified during the walk in such a way that <c>Heap32Next</c> cannot continue.
/// </para>
/// </returns>
/// <remarks>
/// <para>To retrieve information for the first block of a heap, use the Heap32First function.</para>
/// <para>
/// The <c>Heap32Next</c> function does not maintain a reference to the target process. If the target process dies, the system may
/// create a new process using the same process identifier. Therefore, the caller should maintain a reference to the target process
/// as long as it is using <c>Heap32Next</c>.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Heap List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-heap32next BOOL Heap32Next( LPHEAPENTRY32 lphe );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "cc3becd0-edba-47cf-ac2d-26a5d98390e7")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Heap32Next(ref HEAPENTRY32 lphe);
/// <summary>
/// <para>Retrieves information about the first module associated with a process.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lpme">
/// <para>A pointer to a MODULEENTRY32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the first entry of the module list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if no modules exist or the snapshot does not
/// contain module information.
/// </para>
/// </returns>
/// <remarks>
/// <para>The calling application must set the <c>dwSize</c> member of MODULEENTRY32 to the size, in bytes, of the structure.</para>
/// <para>To retrieve information about other modules associated with the specified process, use the Module32Next function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Module List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-module32first BOOL Module32First( HANDLE hSnapshot,
// LPMODULEENTRY32 lpme );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "bb41cab9-13a1-469d-bf76-68c172e982f6")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Module32First(IntPtr hSnapshot, out MODULEENTRY32 lpme);
/// <summary>
/// <para>Retrieves information about the next module associated with a process or thread.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lpme">
/// <para>A pointer to a MODULEENTRY32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the next entry of the module list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if no more modules exist.
/// </para>
/// </returns>
/// <remarks>
/// <para>To retrieve information about first module associated with a process, use the Module32First function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Module List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-module32next BOOL Module32Next( HANDLE hSnapshot,
// LPMODULEENTRY32 lpme );
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("tlhelp32.h", MSDNShortId = "88ec1af4-bae7-4cd7-b830-97a98fb337f4")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Module32Next(IntPtr hSnapshot, out MODULEENTRY32 lpme);
/// <summary>
/// <para>Retrieves information about the first process encountered in a system snapshot.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lppe">
/// <para>
/// A pointer to a PROCESSENTRY32 structure. It contains process information such as the name of the executable file, the process
/// identifier, and the process identifier of the parent process.
/// </para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the first entry of the process list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if no processes exist or the snapshot does not
/// contain process information.
/// </para>
/// </returns>
/// <remarks>
/// <para>The calling application must set the <c>dwSize</c> member of PROCESSENTRY32 to the size, in bytes, of the structure.</para>
/// <para>To retrieve information about other processes recorded in the same snapshot, use the Process32Next function.</para>
/// <para>Examples</para>
/// <para>For an example, see Taking a Snapshot and Viewing Processes.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-process32first BOOL Process32First( HANDLE hSnapshot,
// LPPROCESSENTRY32 lppe );
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("tlhelp32.h", MSDNShortId = "097790e8-30c2-4b00-9256-fa26e2ceb893")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
/// <summary>
/// <para>Retrieves information about the next process recorded in a system snapshot.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lppe">
/// <para>A pointer to a PROCESSENTRY32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the next entry of the process list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if no processes exist or the snapshot does not
/// contain process information.
/// </para>
/// </returns>
/// <remarks>
/// <para>To retrieve information about the first process recorded in a snapshot, use the Process32First function.</para>
/// <para>Examples</para>
/// <para>For an example, see Taking a Snapshot and Viewing Processes.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-process32next BOOL Process32Next( HANDLE hSnapshot,
// LPPROCESSENTRY32 lppe );
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("tlhelp32.h", MSDNShortId = "843a95fd-27ae-4215-83d0-82fc402b82b6")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
/// <summary>
/// <para>Retrieves information about the first thread of any process encountered in a system snapshot.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lpte">
/// <para>A pointer to a THREADENTRY32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the first entry of the thread list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if no threads exist or the snapshot does not
/// contain thread information.
/// </para>
/// </returns>
/// <remarks>
/// <para>
/// The calling application must set the <c>dwSize</c> member of THREADENTRY32 to the size, in bytes, of the structure.
/// <c>Thread32First</c> changes <c>dwSize</c> to the number of bytes written to the structure. This will never be greater than the
/// initial value of <c>dwSize</c>, but it may be smaller. If the value is smaller, do not rely on the values of any members whose
/// offsets are greater than this value.
/// </para>
/// <para>To retrieve information about other threads recorded in the same snapshot, use the Thread32Next function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Thread List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-thread32first BOOL Thread32First( HANDLE hSnapshot,
// LPTHREADENTRY32 lpte );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "d4cb7a19-850e-43b5-bda5-91be48382d2a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Thread32First(IntPtr hSnapshot, ref THREADENTRY32 lpte);
/// <summary>
/// <para>Retrieves information about the next thread of any process encountered in the system memory snapshot.</para>
/// </summary>
/// <param name="hSnapshot">
/// <para>A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.</para>
/// </param>
/// <param name="lpte">
/// <para>A pointer to a THREADENTRY32 structure.</para>
/// </param>
/// <returns>
/// <para>
/// Returns <c>TRUE</c> if the next entry of the thread list has been copied to the buffer or <c>FALSE</c> otherwise. The
/// <c>ERROR_NO_MORE_FILES</c> error value is returned by the GetLastError function if no threads exist or the snapshot does not
/// contain thread information.
/// </para>
/// </returns>
/// <remarks>
/// <para>To retrieve information about the first thread recorded in a snapshot, use the Thread32First function.</para>
/// <para>Examples</para>
/// <para>For an example, see Traversing the Thread List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-thread32next BOOL Thread32Next( HANDLE hSnapshot,
// LPTHREADENTRY32 lpte );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "5efe514e-626c-4138-97a0-bdad217c424f")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Thread32Next(IntPtr hSnapshot, ref THREADENTRY32 lpte);
/// <summary>
/// <para>Copies memory allocated to another process into an application-supplied buffer.</para>
/// </summary>
/// <param name="th32ProcessID">
/// <para>
/// The identifier of the process whose memory is being copied. This parameter can be zero to copy the memory of the current process.
/// </para>
/// </param>
/// <param name="lpBaseAddress">
/// <para>
/// The base address in the specified process to read. Before transferring any data, the system verifies that all data in the base
/// address and memory of the specified size is accessible for read access. If this is the case, the function proceeds. Otherwise,
/// the function fails.
/// </para>
/// </param>
/// <param name="lpBuffer">
/// <para>A pointer to a buffer that receives the contents of the address space of the specified process.</para>
/// </param>
/// <param name="cbRead">
/// <para>The number of bytes to read from the specified process.</para>
/// </param>
/// <param name="lpNumberOfBytesRead">
/// <para>The number of bytes copied to the specified buffer. If this parameter is <c>NULL</c>, it is ignored.</para>
/// </param>
/// <returns>
/// <para>Returns <c>TRUE</c> if successful.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-toolhelp32readprocessmemory BOOL
// Toolhelp32ReadProcessMemory( DWORD th32ProcessID, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T cbRead, SIZE_T
// *lpNumberOfBytesRead );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("tlhelp32.h", MSDNShortId = "e579b813-32ef-481d-8dc6-f959ec9b6bad")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Toolhelp32ReadProcessMemory(uint th32ProcessID, IntPtr lpBaseAddress, IntPtr lpBuffer, SizeT cbRead, out SizeT lpNumberOfBytesRead);
/// <summary>
/// <para>Describes one entry (block) of a heap that is being examined.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/ns-tlhelp32-tagheapentry32 typedef struct tagHEAPENTRY32 { SIZE_T
// dwSize; HANDLE hHandle; ULONG_PTR dwAddress; SIZE_T dwBlockSize; DWORD dwFlags; DWORD dwLockCount; DWORD dwResvd; DWORD
// th32ProcessID; ULONG_PTR th32HeapID; } HEAPENTRY32;
[PInvokeData("tlhelp32.h", MSDNShortId = "c5f1dc66-d44f-4491-b0b7-961b163d0f1f")]
[StructLayout(LayoutKind.Sequential)]
public struct HEAPENTRY32
{
/// <summary>
/// <para>
/// The size of the structure, in bytes. Before calling the Heap32First function, set this member to . If you do not initialize
/// <c>dwSize</c>, <c>Heap32First</c> fails.
/// </para>
/// </summary>
public SizeT dwSize;
/// <summary>
/// <para>A handle to the heap block.</para>
/// </summary>
public IntPtr hHandle;
/// <summary>
/// <para>The linear address of the start of the block.</para>
/// </summary>
public UIntPtr dwAddress;
/// <summary>
/// <para>The size of the heap block, in bytes.</para>
/// </summary>
public SizeT dwBlockSize;
/// <summary>
/// <para>This member can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>LF32_FIXED</term>
/// <term>The memory block has a fixed (unmovable) location.</term>
/// </item>
/// <item>
/// <term>LF32_FREE</term>
/// <term>The memory block is not used.</term>
/// </item>
/// <item>
/// <term>LF32_MOVEABLE</term>
/// <term>The memory block location can be moved.</term>
/// </item>
/// </list>
/// </summary>
public uint dwFlags;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public uint dwLockCount;
/// <summary>
/// <para>Reserved; do not use or alter.</para>
/// </summary>
public uint dwResvd;
/// <summary>
/// <para>The identifier of the process that uses the heap.</para>
/// </summary>
public uint th32ProcessID;
/// <summary>
/// <para>The heap identifier. This is not a handle, and has meaning only to the tool help functions.</para>
/// </summary>
public UIntPtr th32HeapID;
}
/// <summary>
/// <para>Describes an entry from a list that enumerates the heaps used by a specified process.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/ns-tlhelp32-tagheaplist32 typedef struct tagHEAPLIST32 { SIZE_T
// dwSize; DWORD th32ProcessID; ULONG_PTR th32HeapID; DWORD dwFlags; } HEAPLIST32;
[PInvokeData("tlhelp32.h", MSDNShortId = "61e01d23-9f15-44c5-9f6d-45df4809ccad")]
[StructLayout(LayoutKind.Sequential)]
public struct HEAPLIST32
{
/// <summary>
/// <para>
/// The size of the structure, in bytes. Before calling the Heap32ListFirst function, set this member to . If you do not
/// initialize <c>dwSize</c>, <c>Heap32ListFirst</c> will fail.
/// </para>
/// </summary>
public SizeT dwSize;
/// <summary>
/// <para>The identifier of the process to be examined.</para>
/// </summary>
public uint th32ProcessID;
/// <summary>
/// <para>The heap identifier. This is not a handle, and has meaning only to the tool help functions.</para>
/// </summary>
public UIntPtr th32HeapID;
/// <summary>
/// <para>This member can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>HF32_DEFAULT</term>
/// <term>Process's default heap</term>
/// </item>
/// </list>
/// </summary>
public HEAPLIST32_FLAGS dwFlags;
}
/// <summary>
/// <para>Describes an entry from a list of the modules belonging to the specified process.</para>
/// </summary>
/// <remarks>
/// <para>The <c>modBaseAddr</c> and <c>hModule</c> members are valid only in the context of the process specified by th32ProcessID.</para>
/// <para>Examples</para>
/// <para>For an example that uses <c>MODULEENTRY32</c>, see Traversing the Module List.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/ns-tlhelp32-tagmoduleentry32 typedef struct tagMODULEENTRY32 { DWORD
// dwSize; DWORD th32ModuleID; DWORD th32ProcessID; DWORD GlblcntUsage; DWORD ProccntUsage; BYTE *modBaseAddr; DWORD modBaseSize;
// HMODULE hModule; char szModule[MAX_MODULE_NAME32 + 1]; char szExePath[MAX_PATH]; } MODULEENTRY32;
[PInvokeData("tlhelp32.h", MSDNShortId = "305fab35-625c-42e3-a434-e2513e4c8870")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct MODULEENTRY32
{
private const int MAX_MODULE_NAME32 = 255;
/// <summary>
/// <para>
/// The size of the structure, in bytes. Before calling the Module32First function, set this member to . If you do not initialize
/// <c>dwSize</c>, <c>Module32First</c> fails.
/// </para>
/// </summary>
public uint dwSize;
/// <summary>
/// <para>This member is no longer used, and is always set to one.</para>
/// </summary>
public uint th32ModuleID;
/// <summary>
/// <para>The identifier of the process whose modules are to be examined.</para>
/// </summary>
public uint th32ProcessID;
/// <summary>
/// <para>The load count of the module, which is not generally meaningful, and usually equal to 0xFFFF.</para>
/// </summary>
public uint GlblcntUsage;
/// <summary>
/// <para>The load count of the module (same as GlblcntUsage), which is not generally meaningful, and usually equal to 0xFFFF.</para>
/// </summary>
public uint ProccntUsage;
/// <summary>
/// <para>The base address of the module in the context of the owning process.</para>
/// </summary>
public IntPtr modBaseAddr;
/// <summary>
/// <para>The size of the module, in bytes.</para>
/// </summary>
public uint modBaseSize;
/// <summary>
/// <para>A handle to the module in the context of the owning process.</para>
/// </summary>
public IntPtr hModule;
/// <summary>
/// <para>The module name.</para>
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_MODULE_NAME32 + 1)]
public string szModule;
/// <summary>
/// <para>The module path.</para>
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
public string szExePath;
}
/// <summary>
/// <para>Describes an entry from a list of the processes residing in the system address space when a snapshot was taken.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/ns-tlhelp32-tagprocessentry32 typedef struct tagPROCESSENTRY32 {
// DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; ULONG_PTR th32DefaultHeapID; DWORD th32ModuleID; DWORD cntThreads; DWORD
// th32ParentProcessID; LONG pcPriClassBase; DWORD dwFlags; CHAR szExeFile[MAX_PATH]; } PROCESSENTRY32;
[PInvokeData("tlhelp32.h", MSDNShortId = "9e2f7345-52bf-4bfc-9761-90b0b374c727")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PROCESSENTRY32
{
/// <summary>
/// <para>
/// The size of the structure, in bytes. Before calling the Process32First function, set this member to . If you do not
/// initialize <c>dwSize</c>, <c>Process32First</c> fails.
/// </para>
/// </summary>
public uint dwSize;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public uint cntUsage;
/// <summary>
/// <para>The process identifier.</para>
/// </summary>
public uint th32ProcessID;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public UIntPtr th32DefaultHeapID;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public uint th32ModuleID;
/// <summary>
/// <para>The number of execution threads started by the process.</para>
/// </summary>
public uint cntThreads;
/// <summary>
/// <para>The identifier of the process that created this process (its parent process).</para>
/// </summary>
public uint th32ParentProcessID;
/// <summary>
/// <para>The base priority of any threads created by this process.</para>
/// </summary>
public int pcPriClassBase;
/// <summary>
/// <para>This member is no longer used, and is always set to zero.</para>
/// </summary>
public uint dwFlags;
/// <summary>
/// <para>
/// The name of the executable file for the process. To retrieve the full path to the executable file, call the Module32First
/// function and check the <c>szExePath</c> member of the MODULEENTRY32 structure that is returned. However, if the calling
/// process is a 32-bit process, you must call the QueryFullProcessImageName function to retrieve the full path of the executable
/// file for a 64-bit process.
/// </para>
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
public string szExeFile;
}
/// <summary>
/// <para>Describes an entry from a list of the threads executing in the system when a snapshot was taken.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/ns-tlhelp32-tagthreadentry32 typedef struct tagTHREADENTRY32 { DWORD
// dwSize; DWORD cntUsage; DWORD th32ThreadID; DWORD th32OwnerProcessID; LONG tpBasePri; LONG tpDeltaPri; DWORD dwFlags; } THREADENTRY32;
[PInvokeData("tlhelp32.h", MSDNShortId = "923feca1-8807-4752-8a5a-79075688aabd")]
[StructLayout(LayoutKind.Sequential)]
public struct THREADENTRY32
{
/// <summary>
/// <para>
/// The size of the structure, in bytes. Before calling the Thread32First function, set this member to . If you do not initialize
/// <c>dwSize</c>, <c>Thread32First</c> fails.
/// </para>
/// </summary>
public uint dwSize;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public uint cntUsage;
/// <summary>
/// <para>The thread identifier, compatible with the thread identifier returned by the CreateProcess function.</para>
/// </summary>
public uint th32ThreadID;
/// <summary>
/// <para>The identifier of the process that created the thread.</para>
/// </summary>
public uint th32OwnerProcessID;
/// <summary>
/// <para>
/// The kernel base priority level assigned to the thread. The priority is a number from 0 to 31, with 0 representing the lowest
/// possible thread priority. For more information, see <c>KeQueryPriorityThread</c>.
/// </para>
/// </summary>
public int tpBasePri;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public int tpDeltaPri;
/// <summary>
/// <para>This member is no longer used and is always set to zero.</para>
/// </summary>
public uint dwFlags;
}
}
}

File diff suppressed because one or more lines are too long

738
PInvoke/Kernel32/WerApi.cs Normal file
View File

@ -0,0 +1,738 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// <summary>Flags used by WerGetFlags and WerSetFlags.</summary>
[PInvokeData("werapi.h", MSDNShortId = "8c5f08c0-e2d1-448c-9a57-ef19897f64c6")]
[Flags]
public enum WER_FAULT_REPORTING
{
/// <summary>Do not collect heap information in the event of an application crash or non-response.</summary>
WER_FAULT_REPORTING_FLAG_NOHEAP = 1,
/// <summary>Queue critical reports for the specified process. This does not show any UI.</summary>
WER_FAULT_REPORTING_FLAG_QUEUE = 2,
/// <summary>Do not suspend the process threads before reporting the error.</summary>
WER_FAULT_REPORTING_FLAG_DISABLE_THREAD_SUSPENSION = 4,
/// <summary>Queue critical reports and upload from the queue.</summary>
WER_FAULT_REPORTING_FLAG_QUEUE_UPLOAD = 8,
/// <summary>Always show error reporting UI for this process. This is applicable for interactive applications only.</summary>
WER_FAULT_REPORTING_ALWAYS_SHOW_UI = 16,
/// <summary>Undocumented.</summary>
WER_FAULT_REPORTING_NO_UI = 32,
/// <summary>Undocumented.</summary>
WER_FAULT_REPORTING_FLAG_NO_HEAP_ON_QUEUE = 64,
/// <summary>Undocumented.</summary>
WER_FAULT_REPORTING_DISABLE_SNAPSHOT_CRASH = 128,
/// <summary>Undocumented.</summary>
WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG = 256,
/// <summary>Undocumented.</summary>
WER_FAULT_REPORTING_CRITICAL = 512,
/// <summary>Undocumented.</summary>
WER_FAULT_REPORTING_DURABLE = 1024,
}
public enum WER_FILE_TYPE
{
WerFileTypeMicrodump = 1,
WerFileTypeMinidump = 2,
WerFileTypeHeapdump = 3,
WerFileTypeUserDocument = 4,
WerFileTypeOther = 5,
WerFileTypeTriagedump = 6,
WerFileTypeCustomDump = 7,
WerFileTypeAuxiliaryDump = 8,
WerFileTypeEtlTrace = 9,
WerFileTypeMax
}
/// <summary>The file type.</summary>
[PInvokeData("werapi.h", MSDNShortId = "4b4bb1bb-6782-447a-901f-75702256d907")]
public enum WER_REGISTER_FILE_TYPE
{
/// <summary>
/// The document in use by the application at the time of the event. This document is only collected if the Watson server asks
/// for it.
/// </summary>
WerRegFileTypeUserDocument = 1,
/// <summary>Any other type of file.</summary>
WerRegFileTypeOther = 2,
/// <summary>The maximum value for the WER_REGISTER_FILE_TYPE enumeration type.</summary>
WerRegFileTypeMax
}
public enum WER_REPORT_TYPE
{
WerReportNonCritical = 0,
WerReportCritical = 1,
WerReportApplicationCrash = 2,
WerReportApplicationHang = 3,
WerReportKernel = 4,
WerReportInvalid
}
public enum WER_REPORT_UI
{
WerUIAdditionalDataDlgHeader = 1,
WerUIIconFilePath = 2,
WerUIConsentDlgHeader = 3,
WerUIConsentDlgBody = 4,
WerUIOnlineSolutionCheckText = 5,
WerUIOfflineSolutionCheckText = 6,
WerUICloseText = 7,
WerUICloseDlgHeader = 8,
WerUICloseDlgBody = 9,
WerUICloseDlgButtonText = 10,
WerUIMax
}
public enum WER_SUBMIT_RESULT
{
WerReportQueued = 1,
WerReportUploaded = 2,
WerReportDebug = 3,
WerReportFailed = 4,
WerDisabled = 5,
WerReportCancelled = 6,
WerDisabledQueue = 7,
WerReportAsync = 8,
WerCustomAction = 9,
WerThrottled = 10,
WerReportUploadedCab = 11,
WerStorageLocationNotFound = 12,
WerSubmitResultMax
}
/// <summary>
/// <para>Retrieves the fault reporting settings for the specified process.</para>
/// </summary>
/// <param name="hProcess">
/// <para>A handle to the process. This handle must have the PROCESS_VM_READ or PROCESS_QUERY_INFORMATION access right.</para>
/// </param>
/// <param name="pdwFlags">
/// <para>This parameter can contain one or more of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_DISABLE_THREAD_SUSPENSION</term>
/// <term>Do not suspend the process threads before reporting the error.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_NOHEAP</term>
/// <term>Do not collect heap information in the event of an application crash or non-response.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_QUEUE</term>
/// <term>Queue critical reports for the specified process. This does not show any UI.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_QUEUE_UPLOAD</term>
/// <term>Queue critical reports and upload from the queue.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_ALWAYS_SHOW_UI</term>
/// <term>Always show error reporting UI for this process. This is applicable for interactive applications only.</term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-wergetflags HRESULT WerGetFlags( HANDLE hProcess, PDWORD
// pdwFlags );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "8c5f08c0-e2d1-448c-9a57-ef19897f64c6")]
public static extern HRESULT WerGetFlags(IntPtr hProcess, out WER_FAULT_REPORTING pdwFlags);
/// <summary>
/// Registers a process to be included in the error report along with the main application process. Optionally specifies a thread
/// within that registered process to get additional data from.
/// </summary>
/// <param name="processId">The Id of the process to register.</param>
/// <param name="captureExtraInfoForThreadId">The Id of a thread within the registered process from which more information is requested.</param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>The value of processId is 0.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>WER could not allocate a large enough heap for the data.</term>
/// </item>
/// <item>
/// <term>HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)</term>
/// <term>
/// Number of WER registered entries (memory blocks, metadata, files) exceeds max (WER_MAX_REGISTERED_ENTRIES) or number of processes
/// exceeds max (WER_MAX_REGISTERED_DUMPCOLLECTION)
/// </term>
/// </item>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// </list>
/// </para>
/// </returns>
// HRESULT WINAPI WerRegisterAdditionalProcess( DWORD processId, DWORD captureExtraInfoForThreadId); https://msdn.microsoft.com/en-us/library/windows/desktop/mt492585(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Werapi.h", MSDNShortId = "mt492585")]
public static extern HRESULT WerRegisterAdditionalProcess(uint processId, uint captureExtraInfoForThreadId);
/// <summary>
/// <para>Registers app-specific metadata to be collected (in the form of key/value strings) when WER creates an error report.</para>
/// </summary>
/// <param name="key">
/// <para>The "key" string for the metadata element being registered.</para>
/// </param>
/// <param name="value">
/// <para>The value string for the metadata element being registered.</para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>
/// Strings were NULL, key length was greater than 64 characters or was an invalid xml element name, orvalue length was greater than
/// 128 characters or contained characters that were not ASCII printable characters.
/// </term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>WER could not allocate a large enough heap for the data</term>
/// </item>
/// <item>
/// <term>HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)</term>
/// <term>
/// The maximum number of registered entries (WER_MAX_REGISTERED_ENTRIES) or maximum amount of registered metadata
/// (WER_MAX_REGISTERED_METADATA) has been reached.
/// </term>
/// </item>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// This API allows apps to integrate their own app-level telemetry with system-level telemetry (WER) by associating app metadata
/// with crash reports corresponding to their processes.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werregistercustommetadata HRESULT WerRegisterCustomMetadata(
// PCWSTR key, PCWSTR value );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("werapi.h", MSDNShortId = "55FB3110-314A-4327-AA8F-3AF77B7006DD")]
public static extern HRESULT WerRegisterCustomMetadata(string key, string value);
/// <summary>
/// <para>Marks a memory block (that is normally included by default in error reports) to be excluded from the error report.</para>
/// </summary>
/// <param name="address">
/// <para>The starting address of the memory block.</para>
/// </param>
/// <param name="size">
/// <para>The size of the memory block, in bytes.</para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>address is NULL or size is 0.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>WER could not allocate a large enough heap for the data</term>
/// </item>
/// <item>
/// <term>HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)</term>
/// <term>The number of registered entries exceeds the limit (WER_MAX_REGISTERED_ENTRIES).</term>
/// </item>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// This mechanism is intended for applications that hold large amounts of data in memory that aren't useful for root cause debugging
/// and increase the size of the dump file unnecessarily. For example, some Xbox One games hold large amounts of texture data in
/// memory that is included in error dumps by default.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werregisterexcludedmemoryblock HRESULT
// WerRegisterExcludedMemoryBlock( const void *address, DWORD size );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "6CDA8EDD-C8A5-471D-9716-3AB29E571133")]
public static extern HRESULT WerRegisterExcludedMemoryBlock(IntPtr address, uint size);
/// <summary>
/// <para>Registers a file to be collected when WER creates an error report.</para>
/// </summary>
/// <param name="pwzFile">
/// <para>The full path to the file. The maximum length of this path is MAX_PATH characters.</para>
/// </param>
/// <param name="regFileType">
/// <para>The file type. This parameter can be one of the following values from the <c>WER_REGISTER_FILE_TYPE</c> enumeration type.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>WerRegFileTypeMax 3</term>
/// <term>The maximum value for the WER_REGISTER_FILE_TYPE enumeration type.</term>
/// </item>
/// <item>
/// <term>WerRegFileTypeOther 2</term>
/// <term>Any other type of file.</term>
/// </item>
/// <item>
/// <term>WerRegFileTypeUserDocument 1</term>
/// <term>
/// The document in use by the application at the time of the event. This document is only collected if the Watson server asks for it.
/// </term>
/// </item>
/// </list>
/// </param>
/// <param name="dwFlags">
/// <para>This parameter can be one or more of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>WER_FILE_ANONYMOUS_DATA</term>
/// <term>The file does not contain personal information that could be used to identify or contact the user.</term>
/// </item>
/// <item>
/// <term>WER_FILE_DELETE_WHEN_DONE</term>
/// <term>Automatically deletes the file after it is added to the report.</term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)</term>
/// <term>The number of registered memory blocks and files exceeds the limit.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>The registered file is added to the report only when additional data is requested by the server.</para>
/// <para>
/// For crashes and non-responses, the operating system automatically provides error reporting (you do not need to provide any error
/// reporting code in your application). If you use this function to register a file, the operating system will add the file to the
/// error report created at the time of a crash or non-response (this file is added in addition to the files the operating system
/// already collects).
/// </para>
/// <para>
/// For generic event reporting, the application has to use the WerReportAddFile function instead. Alternatively, calling the
/// WerReportSubmit function with the WER_SUBMIT_ADD_REGISTERED_DATA flag will include the files that the <c>WerRegisterFile</c>
/// function added.
/// </para>
/// <para>To remove the file from the list, call the WerUnregisterFile function.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werregisterfile HRESULT WerRegisterFile( PCWSTR pwzFile,
// WER_REGISTER_FILE_TYPE regFileType, DWORD dwFlags );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "4b4bb1bb-6782-447a-901f-75702256d907")]
public static extern HRESULT WerRegisterFile([MarshalAs(UnmanagedType.LPWStr)] string pwzFile, WER_REGISTER_FILE_TYPE regFileType, uint dwFlags);
/// <summary>
/// <para>Registers a memory block to be collected when WER creates an error report.</para>
/// </summary>
/// <param name="pvAddress">
/// <para>The starting address of the memory block.</para>
/// </param>
/// <param name="dwSize">
/// <para>The size of the memory block, in bytes. The maximum value for this parameter is WER_MAX_MEM_BLOCK_SIZE bytes.</para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)</term>
/// <term>The number of registered memory blocks and files exceeds the limit.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// Memory registered with this function is only added to heap or larger dump files. This memory is never added to mini dumps or
/// smaller dump files.
/// </para>
/// <para>
/// For crashes and no response, the operating system automatically provides error reporting (you do not need to provide any error
/// reporting code in your application). If you use this function to register a memory block, the operating system will add the
/// memory block information to the dump file at the time of the crash or non-response. The memory block is added to the dump file
/// for the report only when additional data is requested by the server.
/// </para>
/// <para>
/// For generic event reporting, the application has to call the WER generic event reporting functions directly. To add the memory
/// block to a generic report, call the WerReportAddDump function and then call the WerReportSubmit function and specify the
/// WER_SUBMIT_ADD_REGISTERED_DATA flag.
/// </para>
/// <para>To remove the block from this list, call the WerUnregisterMemoryBlock function.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werregistermemoryblock HRESULT WerRegisterMemoryBlock( PVOID
// pvAddress, DWORD dwSize );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "10fa2bf3-ec12-4c7c-b986-9b22cdaa7319")]
public static extern HRESULT WerRegisterMemoryBlock(IntPtr pvAddress, uint dwSize);
/// <summary>
/// <para>Registers a custom runtime exception handler that is used to provide custom error reporting for crashes.</para>
/// </summary>
/// <param name="pwszOutOfProcessCallbackDll">
/// <para>The name of the exception handler DLL to register.</para>
/// </param>
/// <param name="pContext">
/// <para>A pointer to arbitrary context information that is passed to the handler's callback functions.</para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)</term>
/// <term>
/// The number of registered runtime exception modules exceeds the limit. A process can register up to
/// WER_MAX_REGISTERED_RUNTIME_EXCEPTION_MODULES handlers.
/// </term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// The exception handler is an out-of-process DLL that the WER service loads when a crash or unhandled exception occurs. The DLL
/// must implement and export the following functions:
/// </para>
/// <list type="bullet">
/// <item>
/// <term>OutOfProcessExceptionEventCallback</term>
/// </item>
/// <item>
/// <term>OutOfProcessExceptionEventSignatureCallback</term>
/// </item>
/// <item>
/// <term>OutOfProcessExceptionEventDebuggerLaunchCallback</term>
/// </item>
/// </list>
/// <para>(The DLL must also include the DllMain entry point.)</para>
/// <para>
/// Using an exception handler is more secure and reliable for reporting crash information than the current, in-process event
/// reporting feature. Also, the current generic event reporting feature is suited only for reporting non-fatal errors.
/// </para>
/// <para>
/// This function requires that the pwszOutOfProcessCallbackDll DLL be included in the WER exception handler module list in the
/// registry. After registering an exception handler, if the process crashes or raises an unhandled exception, the WER service loads
/// your exception handler and calls the OutOfProcessExceptionEventCallback callback function., which you use to state your claim on
/// the crash and provide the event name and report parameters count. Note that if the process registers more than one exception
/// handler, the service calls each handler until one of the handlers claims the crash. If no handlers claim the crash, WER defaults
/// to native crash reporting.
/// </para>
/// <para>
/// If an exception handler claims the exception, the WER service calls the OutOfProcessExceptionEventSignatureCallback callback
/// function, which provides the reporting parameters that uniquely define the problem. Then, the WER service calls the
/// OutOfProcessExceptionEventDebuggerLaunchCallback callback to determine whether to offer the user the option of launching a
/// debugger or launching the debugger automatically. The handler can also specify a custom debugger launch string, which will
/// override the default string (the default is the debugger specified in the AeDebug registry key).
/// </para>
/// <para>
/// After the handler has provided the event name, reporting parameters and debugger launch settings, the rest of the error reporting
/// flow continues in the usual way.
/// </para>
/// <para>
/// You must call the WerUnregisterRuntimeExceptionModule function to remove the registration before your process exits. A process
/// can register up to WER_MAX_REGISTERED_RUNTIME_EXCEPTION_MODULES handlers.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werregisterruntimeexceptionmodule HRESULT
// WerRegisterRuntimeExceptionModule( PCWSTR pwszOutOfProcessCallbackDll, PVOID pContext );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "b0fb2c0d-cc98-43cc-a508-e80545377b7f")]
public static extern HRESULT WerRegisterRuntimeExceptionModule([MarshalAs(UnmanagedType.LPWStr)] string pwszOutOfProcessCallbackDll, IntPtr pContext);
/// <summary>
/// <para>Sets the fault reporting settings for the current process.</para>
/// </summary>
/// <param name="dwFlags">
/// <para>The fault reporting settings. You can specify one or more of the following values:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_DISABLE_THREAD_SUSPENSION</term>
/// <term>Do not suspend the process threads before reporting the error.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_NOHEAP</term>
/// <term>Do not collect heap information in the event of an application crash or non-response.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_QUEUE</term>
/// <term>Queue critical reports.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_FLAG_QUEUE_UPLOAD</term>
/// <term>Queue critical reports and upload from the queue.</term>
/// </item>
/// <item>
/// <term>WER_FAULT_REPORTING_ALWAYS_SHOW_UI</term>
/// <term>Always show error reporting UI for this process. This is applicable for interactive applications only.</term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-wersetflags HRESULT WerSetFlags( DWORD dwFlags );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "2a71203f-3a08-461f-a230-e3fee00d9d99")]
public static extern HRESULT WerSetFlags(WER_FAULT_REPORTING dwFlags);
/// <summary>
/// <para>Removes a process from the list of additional processes to be included in the error report.</para>
/// </summary>
/// <param name="processId">
/// <para>The Id of the process to remove. It must have been previously registered with WerRegisterAdditionalProcess.</para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>WER_E_NOT_FOUND</term>
/// <term>The list of registered processes does not contain the specified process.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werunregisteradditionalprocess HRESULT
// WerUnregisterAdditionalProcess( DWORD processId );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "CE840EE8-5EB6-4F0F-935E-5DA9097E950F")]
public static extern HRESULT WerUnregisterAdditionalProcess(uint processId);
/// <summary>
/// <para>Removes an item of app-specific metadata being collected during error reporting for the application.</para>
/// </summary>
/// <param name="key">
/// <para>
/// The "key" string for the metadata element being removed. It must have been previously registered with the
/// WerRegisterCustomMetadata function.
/// </para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>WER_E_NOT_FOUND</term>
/// <term>WER could not find the metadata item to remove.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werunregistercustommetadata HRESULT
// WerUnregisterCustomMetadata( PCWSTR key );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "29DB2CE5-2A96-450B-96C8-082B786613F9")]
public static extern HRESULT WerUnregisterCustomMetadata([MarshalAs(UnmanagedType.LPWStr)] string key);
/// <summary>
/// <para>Removes a memory block that was previously marked as excluded (it will again be included in error reports).</para>
/// </summary>
/// <param name="address">
/// <para>
/// The starting address of the memory block. This memory block must have been registered using the WerRegisterExcludedMemoryBlock function.
/// </para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error code.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werunregisterexcludedmemoryblock HRESULT
// WerUnregisterExcludedMemoryBlock( const void *address );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "99FF746E-8EFC-47DB-AEE6-EC46F7BC7F0B")]
public static extern HRESULT WerUnregisterExcludedMemoryBlock(IntPtr address);
/// <summary>Removes a file from the list of files to be added to reports generated for the current process.</summary>
/// <param name="pwzFilePath">The full path to the file. This file must have been registered using the <c>WerRegisterFile</c> function.</param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error code.</para>
/// <para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>WER_E_NOT_FOUND</term>
/// <term>The list of registered files does not contain the specified file.</term>
/// </item>
/// </list>
/// </para>
/// </returns>
// HRESULT WINAPI WerUnregisterFile( _In_ PCWSTR pwzFilePath); https://msdn.microsoft.com/en-us/library/windows/desktop/bb513630(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Werapi.h", MSDNShortId = "bb513630")]
public static extern HRESULT WerUnregisterFile([MarshalAs(UnmanagedType.LPWStr)] string pwzFilePath);
/// <summary>
/// <para>Removes a memory block from the list of data to be collected during error reporting for the application.</para>
/// </summary>
/// <param name="pvAddress">
/// <para>
/// The starting address of the memory block. This memory block must have been registered using the WerRegisterMemoryBlock function.
/// </para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error code.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>WER_E_NOT_FOUND</term>
/// <term>The list of registered memory blocks does not contain the specified memory block.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werunregistermemoryblock HRESULT WerUnregisterMemoryBlock(
// PVOID pvAddress );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "016800e8-4a03-40f6-9dba-54cd9082eb48")]
public static extern HRESULT WerUnregisterMemoryBlock(IntPtr pvAddress);
/// <summary>
/// <para>Removes the registration of your WER exception handler.</para>
/// </summary>
/// <param name="pwszOutOfProcessCallbackDll">
/// <para>The name of the exception handler DLL whose registration you want to remove.</para>
/// </param>
/// <param name="pContext">
/// <para>A pointer to arbitrary context information that was passed to the callback.</para>
/// </param>
/// <returns>
/// <para>This function returns <c>S_OK</c> on success or an error code on failure, including the following error code.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>WER_E_INVALID_STATE</term>
/// <term>The process state is not valid. For example, the process is in application recovery mode.</term>
/// </item>
/// <item>
/// <term>WER_E_NOT_FOUND</term>
/// <term>The list of registered runtime exception handlers does not contain the specified exception handler.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>To register your runtime exception handler, call the WerRegisterRuntimeExceptionModule function.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/werapi/nf-werapi-werunregisterruntimeexceptionmodule HRESULT
// WerUnregisterRuntimeExceptionModule( PCWSTR pwszOutOfProcessCallbackDll, PVOID pContext );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("werapi.h", MSDNShortId = "1a315923-b554-4363-a607-076690fc76a1")]
public static extern HRESULT WerUnregisterRuntimeExceptionModule([MarshalAs(UnmanagedType.LPWStr)] string pwszOutOfProcessCallbackDll, IntPtr pContext);
}
}

View File

@ -92,33 +92,65 @@ namespace Vanara.PInvoke
CALLBACK_STREAM_SWITCH = 0x00000001, CALLBACK_STREAM_SWITCH = 0x00000001,
} }
/// <summary>Flags that specify how the file is to be copied.</summary> /// <summary>Flags used by <see cref="COPYFILE2_EXTENDED_PARAMETERS"/>.</summary>
[PInvokeData("winbase.h", MSDNShortId = "a8da62e5-bc49-4aff-afaa-e774393b7120")]
[Flags] [Flags]
public enum COPY_FILE public enum COPY_FILE : uint
{ {
/// <summary>An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted.</summary> /// <summary>The copy will be attempted even if the destination file cannot be encrypted.</summary>
COPY_FILE_ALLOW_DECRYPTED_DESTINATION = 0x00000008, COPY_FILE_ALLOW_DECRYPTED_DESTINATION = 0x00000008,
/// <summary> /// <summary>
/// If the source file is a symbolic link, the destination file is also a symbolic link pointing to the same file that the source symbolic link is /// If the source file is a symbolic link, the destination file is also a symbolic link pointing to the same file as the source
/// pointing to. /// symbolic link.
/// <para>Windows Server 2003 and Windows XP: This value is not supported.</para>
/// </summary> /// </summary>
COPY_FILE_COPY_SYMLINK = 0x00000800, COPY_FILE_COPY_SYMLINK = 0x00000800,
/// <summary>The copy operation fails immediately if the target file already exists.</summary>
COPY_FILE_FAIL_IF_EXISTS = 0x00000001,
/// <summary> /// <summary>
/// The copy operation is performed using unbuffered I/O, bypassing system I/O cache resources. Recommended for very large file transfers. /// If the destination file exists the copy operation fails immediately. If a file or directory exists with the destination name
/// <para>Windows Server 2003 and Windows XP: This value is not supported.</para> /// then the CopyFile2 function call will fail with either HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) or
/// HRESULT_FROM_WIN32(ERROR_FILE_EXISTS). If COPY_FILE_RESUME_FROM_PAUSE is also specified then a failure is only triggered if
/// the destination file does not have a valid restart header.
/// </summary>
COPY_FILE_FAIL_IF_EXISTS = 0x00000001,
/// <summary>
/// The copy is performed using unbuffered I/O, bypassing the system cache resources. This flag is recommended for very large
/// file copies. It is not recommended to pause copies that are using this flag.
/// </summary> /// </summary>
COPY_FILE_NO_BUFFERING = 0x00001000, COPY_FILE_NO_BUFFERING = 0x00001000,
/// <summary>The file is copied and the original file is opened for write access.</summary>
/// <summary>Do not attempt to use the Windows Copy Offload mechanism. This is not generally recommended.</summary>
COPY_FILE_NO_OFFLOAD = 0x00040000,
/// <summary>The file is copied and the source file is opened for write access.</summary>
COPY_FILE_OPEN_SOURCE_FOR_WRITE = 0x00000004, COPY_FILE_OPEN_SOURCE_FOR_WRITE = 0x00000004,
/// <summary> /// <summary>
/// Progress of the copy is tracked in the target file in case the copy fails. The failed copy can be restarted at a later time by specifying the /// The file is copied in a manner that can be restarted if the same source and destination filenames are used again. This is slower.
/// same values for lpExistingFileName and lpNewFileName as those used in the call that failed. This can significantly slow down the copy operation
/// as the new file may be flushed multiple times during the copy operation.
/// </summary> /// </summary>
COPY_FILE_RESTARTABLE = 0x00000002, COPY_FILE_RESTARTABLE = 0x00000002,
/// <summary>
/// The copy is attempted, specifying ACCESS_SYSTEM_SECURITY for the source file and ACCESS_SYSTEM_SECURITY | WRITE_DAC |
/// WRITE_OWNER for the destination file. If these requests are denied the access request will be reduced to the highest
/// privilege level for which access is granted. For more information see SACL Access Right. This can be used to allow the
/// CopyFile2ProgressRoutine callback to perform operations requiring higher privileges, such as copying the security attributes
/// for the file.
/// </summary>
COPY_FILE_REQUEST_SECURITY_PRIVILEGES = 0x00002000,
/// <summary>
/// The destination file is examined to see if it was copied using COPY_FILE_RESTARTABLE. If so the copy is resumed. If not the
/// file will be fully copied.
/// </summary>
COPY_FILE_RESUME_FROM_PAUSE = 0x00004000,
/// <summary>Undocumented.</summary>
COPY_FILE_IGNORE_EDP_BLOCK = 0x00400000,
/// <summary>Undocumented.</summary>
COPY_FILE_IGNORE_SOURCE_ENCRYPTION = 0x00800000,
} }
/// <summary> /// <summary>

View File

@ -43,13 +43,17 @@ namespace Vanara.PInvoke
ES_USER_PRESENT = 0x00000004, ES_USER_PRESENT = 0x00000004,
} }
/// <summary>Flags for <c>CreateFiberEx</c>.</summary> /// <summary>Flags used by <see cref="ConvertThreadToFiberEx"/>.</summary>
[PInvokeData("winbase.h", MSDNShortId = "cb0473f8-bc49-44c9-a8b7-6d5b55aa37a5")]
public enum FIBER_FLAG public enum FIBER_FLAG
{ {
/// <summary>The floating-point state on x86 systems is not switched and data can be corrupted if a fiber uses floating-point arithmetic.</summary> /// <summary>
FIBER_FLAG_UNSPECIFIED = 0, /// The floating-point state on x86 systems is not switched and data can be corrupted if a fiber uses floating-point arithmetic.
/// </summary>
FIBER_FLAG_NONE = 0,
/// <summary>The floating-point state is switched for the fiber.</summary> /// <summary>The floating-point state is switched for the fiber.</summary>
FIBER_FLAG_FLOAT_SWITCH = 1 FIBER_FLAG_FLOAT_SWITCH = 1,
} }
/// <summary>Converts the current fiber into a thread.</summary> /// <summary>Converts the current fiber into a thread.</summary>
@ -76,6 +80,39 @@ namespace Vanara.PInvoke
[PInvokeData("WinBase.h", MSDNShortId = "ms682115")] [PInvokeData("WinBase.h", MSDNShortId = "ms682115")]
public static extern IntPtr ConvertThreadToFiber([In] IntPtr lpParameter); public static extern IntPtr ConvertThreadToFiber([In] IntPtr lpParameter);
/// <summary>
/// <para>Converts the current thread into a fiber. You must convert a thread into a fiber before you can schedule other fibers.</para>
/// </summary>
/// <param name="lpParameter">
/// <para>A pointer to a variable that is passed to the fiber. The fiber can retrieve this data by using the GetFiberData macro.</para>
/// </param>
/// <param name="dwFlags">
/// <para>
/// If this parameter is zero, the floating-point state on x86 systems is not switched and data can be corrupted if a fiber uses
/// floating-point arithmetic. If this parameter is FIBER_FLAG_FLOAT_SWITCH, the floating-point state is switched for the fiber.
/// </para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the address of the fiber.</para>
/// <para>If the function fails, the return value is NULL. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// Only fibers can execute other fibers. If a thread needs to execute a fiber, it must call ConvertTheadToFiber or
/// <c>ConvertThreadToFiberEx</c> to create an area in which to save fiber state information. The thread is now the current fiber.
/// The state information for this fiber includes the fiber data specified by .
/// </para>
/// <para>
/// To compile an application that uses this function, define _WIN32_WINNT as 0x0400 or later. For more information, see Using the
/// Windows Headers.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-convertthreadtofiberex LPVOID ConvertThreadToFiberEx(
// LPVOID lpParameter, DWORD dwFlags );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winbase.h", MSDNShortId = "cb0473f8-bc49-44c9-a8b7-6d5b55aa37a5")]
public static extern IntPtr ConvertThreadToFiberEx(IntPtr lpParameter, FIBER_FLAG dwFlags);
/// <summary> /// <summary>
/// Allocates a fiber object, assigns it a stack, and sets up execution to begin at the specified start address, typically the fiber function. This /// Allocates a fiber object, assigns it a stack, and sets up execution to begin at the specified start address, typically the fiber function. This
/// function does not schedule the fiber. /// function does not schedule the fiber.

File diff suppressed because it is too large Load Diff

View File

@ -1371,22 +1371,40 @@ namespace Vanara.PInvoke
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetConsoleCursorInfo(IntPtr hConsoleOutput, ref CONSOLE_CURSOR_INFO lpConsoleCursorInfo); public static extern bool SetConsoleCursorInfo(IntPtr hConsoleOutput, ref CONSOLE_CURSOR_INFO lpConsoleCursorInfo);
/// <summary>Sets the cursor position in the specified console screen buffer.</summary> /// <summary>
/// <para>Sets the cursor position in the specified console screen buffer.</para>
/// </summary>
/// <param name="hConsoleOutput"> /// <param name="hConsoleOutput">
/// A handle to the console screen buffer. The handle must have the <c>GENERIC_READ</c> access right. For more information, see Console Buffer Security /// <para>
/// and Access Rights. /// [in]A handle to the console screen buffer. The handle must have the <c>GENERIC_READ</c> access right. For more information, see
/// Console Buffer Security and Access Rights.
/// </para>
/// </param> /// </param>
/// <param name="dwCursorPosition"> /// <param name="dwCursorPosition">
/// A <c>COORD</c> structure that specifies the new cursor position, in characters. The coordinates are the column and row of a screen buffer character /// <para>
/// cell. The coordinates must be within the boundaries of the console screen buffer. /// [in]A <c>COORD</c> structure that specifies the new cursor position, in characters. The coordinates are the column and row of a
/// screen buffer character cell. The coordinates must be within the boundaries of the console screen buffer.
/// </para>
/// </param> /// </param>
/// <returns> /// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para> /// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call <c>GetLastError</c>.</para> /// <para>If the function fails, the return value is zero. To get extended error information, call <c>GetLastError</c>.</para>
/// </returns> /// </returns>
/// <remarks>
/// <para>
/// The cursor position determines where characters written by the <c>WriteFile</c> or <c>WriteConsole</c> function, or echoed by the
/// <c>ReadFile</c> or <c>ReadConsole</c> function, are displayed. To determine the current position of the cursor, use the
/// <c>GetConsoleScreenBufferInfo</c> function.
/// </para>
/// <para>
/// If the new cursor position is not within the boundaries of the console screen buffer's window, the window origin changes to make
/// the cursor visible.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/console/setconsolecursorposition
// BOOL WINAPI SetConsoleCursorPosition( _In_ HANDLE hConsoleOutput, _In_ COORD dwCursorPosition ); // BOOL WINAPI SetConsoleCursorPosition( _In_ HANDLE hConsoleOutput, _In_ COORD dwCursorPosition );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Wincon.h", MSDNShortId = "")] [PInvokeData("Wincon.h", MSDNShortId = "8e9abada-a64e-429f-8286-ced1169c7104")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetConsoleCursorPosition(IntPtr hConsoleOutput, COORD dwCursorPosition); public static extern bool SetConsoleCursorPosition(IntPtr hConsoleOutput, COORD dwCursorPosition);

View File

@ -1,11 +1,216 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using static Vanara.Extensions.BitHelper;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace Vanara.PInvoke namespace Vanara.PInvoke
{ {
public static partial class Kernel32 public static partial class Kernel32
{ {
/// <summary>
/// <para>
/// An application-defined function previously registered with the AddSecureMemoryCacheCallback function that is called when a
/// secured memory range is freed or its protections are changed.
/// </para>
/// <para>
/// The <c>PSECURE_MEMORY_CACHE_CALLBACK</c> type defines a pointer to this callback function. is a placeholder for the
/// application-defined function name.
/// </para>
/// </summary>
/// <param name="Addr">
/// <para>The starting address of the memory range.</para>
/// </param>
/// <param name="Range">
/// <para>The size of the memory range, in bytes.</para>
/// </param>
/// <returns>
/// <para>The return value indicates the success or failure of this function.</para>
/// <para>If the caller has secured the specified memory range, this function should unsecure the memory and return <c>TRUE</c>.</para>
/// <para>If the caller has not secured the specified memory range, this function should return <c>FALSE</c>.</para>
/// </returns>
/// <remarks>
/// <para>
/// After the callback function is registered, it is called after any attempt to free the specified memory range or change its
/// protections. If the application has secured any part of the specified memory range, the callback function must invalidate all of
/// the application's cached memory mappings for the secured memory range, unsecure the secured parts of the memory range, and return
/// <c>TRUE</c>. Otherwise it must return <c>FALSE</c>.
/// </para>
/// <para>
/// The application secures and unsecures a memory range by sending requests to a device driver, which uses the MmSecureVirtualMemory
/// and MmUnsecureVirtualMemory functions to actually secure and unsecure the range. Operations on other types of secured or locked
/// memory do not trigger this callback.
/// </para>
/// <para>
/// Examples of function calls that trigger the callback function include calls to the VirtualFree, VirtualFreeEx, VirtualProtect,
/// VirtualProtectEx, and UnmapViewOfFile functions.
/// </para>
/// <para>
/// The callback function can also be triggered by a heap operation. In this case, the function must not perform any further
/// operations on the heap that triggered the callback. This includes calling heap functions on a private heap or the process's
/// default heap, or calling standard library functions such as <c>malloc</c> and <c>free</c>, which implicitly use the process's
/// default heap.
/// </para>
/// <para>To unregister the callback function, use the RemoveSecureMemoryCacheCallback function.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/nc-winnt-psecure_memory_cache_callback
// BOOLEAN PsecureMemoryCacheCallback( PVOID Addr, SIZE_T Range ) {...}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
[PInvokeData("winnt.h", MSDNShortId = "abde4b6f-7cd8-4a4b-9b00-f035b2c29054")]
[return: MarshalAs(UnmanagedType.U1)]
public delegate bool PsecureMemoryCacheCallback(IntPtr Addr, SizeT Range);
/// <summary>
/// <para>The application-defined user-mode scheduling (UMS) scheduler entry point function associated with a UMS completion list.</para>
/// <para>
/// The <c>PUMS_SCHEDULER_ENTRY_POINT</c> type defines a pointer to this function. UmsSchedulerProc is a placeholder for the
/// application-defined function name.
/// </para>
/// </summary>
/// <param name="Reason">
/// <para>The reason the scheduler entry point is being called. This parameter can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>UmsSchedulerStartup 0</term>
/// <term>
/// A UMS scheduler thread was created. The entry point is called with this reason once each time EnterUmsSchedulingMode is called.
/// </term>
/// </item>
/// <item>
/// <term>UmsSchedulerThreadBlocked 1</term>
/// <term>A UMS worker thread blocked.</term>
/// </item>
/// <item>
/// <term>UmsSchedulerThreadYield 2</term>
/// <term>An executing UMS worker thread yielded control by calling the UmsThreadYield function.</term>
/// </item>
/// </list>
/// </param>
/// <param name="ActivationPayload">
/// <para>If the Reason parameter is <c>UmsSchedulerStartup</c>, this parameter is NULL.</para>
/// <para>
/// If the Reason parameter is <c>UmsSchedulerThreadBlocked</c>, bit 0 of this parameter indicates the type of activity that was
/// being serviced when the UMS worker thread blocked.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>0</term>
/// <term>
/// The thread blocked on a trap (for example, a hard page fault) or an interrupt (for example, an asynchronous procedure call).
/// </term>
/// </item>
/// <item>
/// <term>1</term>
/// <term>The thread blocked on a system call.</term>
/// </item>
/// </list>
/// <para>
/// If the Reason parameter is <c>UmsSchedulerThreadYield</c>, this parameter is a pointer to the UMS thread context of the UMS
/// worker thread that yielded.
/// </para>
/// </param>
/// <param name="SchedulerParam">
/// <para>
/// If the Reason parameter is <c>UmsSchedulerStartup</c>, this parameter is the <c>SchedulerParam</c> member of the
/// UMS_SCHEDULER_STARTUP_INFO structure passed to the EnterUmsSchedulingMode function that triggered the entry point call.
/// </para>
/// <para>
/// If the Reason parameter is <c>UmsSchedulerThreadYield</c> this parameter is the SchedulerParam parameter passed to the
/// UmsThreadYield function that triggered the entry point call.
/// </para>
/// <para>If the Reason parameter is <c>UmsSchedulerThreadBlocked</c>, this parameter is NULL.</para>
/// </param>
/// <returns>
/// <para>This function does not return a value.</para>
/// </returns>
/// <remarks>
/// <para>
/// The UmsSchedulerProc function pointer type is defined as <c>PUMS_SCHEDULER_ENTRY_POINT</c> in WinBase.h. The underlying function
/// type is defined as <c>RTL_UMS_SCHEDULER_ENTRY_POINT</c> in WinNT.h
/// </para>
/// <para>
/// Each UMS scheduler thread has an associated UmsSchedulerProc entry point function that is specified when the thread calls the
/// EnterUmsSchedulingMode function. The system calls the scheduler entry point function with a reason of <c>UmsSchedulerStartup</c>
/// when the scheduler thread is converted for UMS.
/// </para>
/// <para>
/// Subsequently, when a UMS worker thread that is running on the scheduler thread yields or blocks, the system calls the scheduler
/// thread's entry point function with a pointer to the UMS thread context of the worker thread.
/// </para>
/// <para>
/// The application's scheduler is responsible for selecting the next UMS worker thread to run. The scheduler implements all policies
/// that influence execution of its UMS threads, including processor affinity and thread priority. For example, a scheduler might
/// give priority to I/O-intensive threads, or it might run threads on a first-come, first-served basis. This logic can be
/// implemented in the scheduler entry point function or elsewhere in the application.
/// </para>
/// <para>
/// When a blocked UMS worker thread becomes unblocked, the system queues the unblocked thread to the associated completion list and
/// signals the completion list event. To retrieve UMS worker threads from the completion list, use the DequeueUmsCompletionListItems function.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/nc-winnt-rtl_ums_scheduler_entry_point RTL_UMS_SCHEDULER_ENTRY_POINT
// RtlUmsSchedulerEntryPoint; void RtlUmsSchedulerEntryPoint( RTL_UMS_SCHEDULER_REASON Reason, ULONG_PTR ActivationPayload, PVOID
// SchedulerParam ) {...}
[PInvokeData("winnt.h", MSDNShortId = "10de1c48-255d-45c3-acf0-25f8a564b585")]
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void RtlUmsSchedulerEntryPoint(RTL_UMS_SCHEDULER_REASON Reason, UIntPtr ActivationPayload, IntPtr SchedulerParam);
/// <summary>Used by thread context functions.</summary>
[PInvokeData("winnt.h")]
[Flags]
public enum CONTEXT_FLAG : uint
{
/// <summary>Undocumented.</summary>
CONTEXT_AMD64 = 0x00100000,
/// <summary>Undocumented.</summary>
CONTEXT_CONTROL = (CONTEXT_AMD64 | 0x00000001),
/// <summary>Undocumented.</summary>
CONTEXT_INTEGER = (CONTEXT_AMD64 | 0x00000002),
/// <summary>Undocumented.</summary>
CONTEXT_SEGMENTS = (CONTEXT_AMD64 | 0x00000004),
/// <summary>Undocumented.</summary>
CONTEXT_FLOATING_POINT = (CONTEXT_AMD64 | 0x00000008),
/// <summary>Undocumented.</summary>
CONTEXT_DEBUG_REGISTERS = (CONTEXT_AMD64 | 0x00000010),
/// <summary>Undocumented.</summary>
CONTEXT_FULL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT),
/// <summary>Undocumented.</summary>
CONTEXT_ALL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS),
/// <summary>Undocumented.</summary>
CONTEXT_XSTATE = (CONTEXT_AMD64 | 0x00000040),
/// <summary>Undocumented.</summary>
CONTEXT_KERNEL_DEBUGGER = 0x04000000,
/// <summary>Undocumented.</summary>
CONTEXT_EXCEPTION_ACTIVE = 0x08000000,
/// <summary>Undocumented.</summary>
CONTEXT_SERVICE_ACTIVE = 0x10000000,
/// <summary>Undocumented.</summary>
CONTEXT_EXCEPTION_REQUEST = 0x40000000,
/// <summary>Undocumented.</summary>
CONTEXT_EXCEPTION_REPORTING = 0x80000000
}
/// <summary>The flags that control the enforcement of the minimum and maximum working set sizes.</summary> /// <summary>The flags that control the enforcement of the minimum and maximum working set sizes.</summary>
[PInvokeData("winnt.h")] [PInvokeData("winnt.h")]
[Flags] [Flags]
@ -13,74 +218,462 @@ namespace Vanara.PInvoke
{ {
/// <summary>The working set will not fall below the minimum working set limit.</summary> /// <summary>The working set will not fall below the minimum working set limit.</summary>
QUOTA_LIMITS_HARDWS_MIN_ENABLE = 0x00000001, QUOTA_LIMITS_HARDWS_MIN_ENABLE = 0x00000001,
/// <summary>The working set may fall below the minimum working set limit if memory demands are high.</summary> /// <summary>The working set may fall below the minimum working set limit if memory demands are high.</summary>
QUOTA_LIMITS_HARDWS_MIN_DISABLE = 0x00000002, QUOTA_LIMITS_HARDWS_MIN_DISABLE = 0x00000002,
/// <summary>The working set will not exceed the maximum working set limit.</summary> /// <summary>The working set will not exceed the maximum working set limit.</summary>
QUOTA_LIMITS_HARDWS_MAX_ENABLE = 0x00000004, QUOTA_LIMITS_HARDWS_MAX_ENABLE = 0x00000004,
/// <summary>The working set may exceed the maximum working set limit if there is abundant memory.</summary> /// <summary>The working set may exceed the maximum working set limit if there is abundant memory.</summary>
QUOTA_LIMITS_HARDWS_MAX_DISABLE = 0x00000008, QUOTA_LIMITS_HARDWS_MAX_DISABLE = 0x00000008,
/// <summary>The quota limits use default limits</summary> /// <summary>The quota limits use default limits</summary>
QUOTA_LIMITS_USE_DEFAULT_LIMITS = 0x00000010, QUOTA_LIMITS_USE_DEFAULT_LIMITS = 0x00000010,
} }
/// <summary>Used by <see cref="RtlUmsSchedulerEntryPoint"/>.</summary>
[PInvokeData("winnt.h", MSDNShortId = "10de1c48-255d-45c3-acf0-25f8a564b585")]
public enum RTL_UMS_SCHEDULER_REASON
{
/// <summary>
/// A UMS scheduler thread was created. The entry point is called with this reason once each time EnterUmsSchedulingMode is called.
/// </summary>
UmsSchedulerStartup = 0,
/// <summary>A UMS worker thread blocked.</summary>
UmsSchedulerThreadBlocked = 1,
/// <summary>An executing UMS worker thread yielded control by calling the UmsThreadYield function.</summary>
UmsSchedulerThreadYield = 2,
}
/// <summary>
/// <para>Represents classes of information about user-mode scheduling (UMS) threads.</para>
/// <para>This enumeration is used by the QueryUmsThreadInformation and SetUmsThreadInformation functions.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ne-winnt-_rtl_ums_thread_info_class typedef enum
// _RTL_UMS_THREAD_INFO_CLASS { UmsThreadInvalidInfoClass , UmsThreadUserContext , UmsThreadPriority , UmsThreadAffinity ,
// UmsThreadTeb , UmsThreadIsSuspended , UmsThreadIsTerminated , UmsThreadMaxInfoClass } RTL_UMS_THREAD_INFO_CLASS, *PRTL_UMS_THREAD_INFO_CLASS;
[PInvokeData("winnt.h", MSDNShortId = "2d6730b2-4d01-45f5-9514-0d91806f50d5")]
public enum RTL_UMS_THREAD_INFO_CLASS
{
/// <summary>Reserved.</summary>
UmsThreadInvalidInfoClass,
/// <summary>Application-defined information stored in a UMS thread context.</summary>
UmsThreadUserContext,
/// <summary>Reserved.</summary>
UmsThreadPriority,
/// <summary>Reserved.</summary>
UmsThreadAffinity,
/// <summary>
/// The thread execution block (TEB) for a UMS thread. This information class can only be queried; it cannot be set.
/// </summary>
UmsThreadTeb,
/// <summary>The suspension status of the thread. This information can only be queried; it cannot be set.</summary>
UmsThreadIsSuspended,
/// <summary>The termination status of the thread. This information can only be queried; it cannot be set.</summary>
UmsThreadIsTerminated,
/// <summary>Reserved.</summary>
UmsThreadMaxInfoClass,
}
[PInvokeData("winnt.h")] [PInvokeData("winnt.h")]
[Flags] [Flags]
public enum SECTION_MAP : uint public enum SECTION_MAP : uint
{ {
SECTION_QUERY = 0x0001, SECTION_QUERY = 0x0001,
SECTION_MAP_WRITE = 0x0002, SECTION_MAP_WRITE = 0x0002,
SECTION_MAP_READ = 0x0004, SECTION_MAP_READ = 0x0004,
SECTION_MAP_EXECUTE = 0x0008, SECTION_MAP_EXECUTE = 0x0008,
SECTION_EXTEND_SIZE = 0x0010, SECTION_EXTEND_SIZE = 0x0010,
SECTION_MAP_EXECUTE_EXPLICIT = 0x0020, SECTION_MAP_EXECUTE_EXPLICIT = 0x0020,
SECTION_ALL_ACCESS = ACCESS_MASK.STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE, SECTION_ALL_ACCESS = ACCESS_MASK.STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE,
} }
/// <summary> /// <summary>
/// A mask that indicates the member of the OSVERSIONINFOEX structure whose comparison operator is being set. This value corresponds to one of the bits /// The operator to be used for the comparison. The VerifyVersionInfo function uses this operator to compare a specified attribute
/// specified in the dwTypeMask parameter for the VerifyVersionInfo function. /// value to the corresponding value for the currently running system.
/// </summary>
public enum VERSION_CONDITION : byte
{
/// <summary>The current value must be equal to the specified value.</summary>
VER_EQUAL = 1,
/// <summary>The current value must be greater than the specified value.</summary>
VER_GREATER,
/// <summary>The current value must be greater than or equal to the specified value.</summary>
VER_GREATER_EQUAL,
/// <summary>The current value must be less than the specified value.</summary>
VER_LESS,
/// <summary>The current value must be less than or equal to the specified value.</summary>
VER_LESS_EQUAL,
/// <summary>All product suites specified in the wSuiteMask member must be present in the current system.</summary>
VER_AND,
/// <summary>At least one of the specified product suites must be present in the current system.</summary>
VER_OR,
}
/// <summary>
/// A mask that indicates the member of the OSVERSIONINFOEX structure whose comparison operator is being set. This value corresponds
/// to one of the bits specified in the dwTypeMask parameter for the VerifyVersionInfo function.
/// </summary> /// </summary>
[Flags] [Flags]
public enum VERSION_MASK : uint public enum VERSION_MASK : uint
{ {
/// <summary>dwMinorVersion</summary> /// <summary>dwMinorVersion</summary>
VER_MINORVERSION = 0x0000001, VER_MINORVERSION = 0x0000001,
/// <summary>dwMajorVersion</summary> /// <summary>dwMajorVersion</summary>
VER_MAJORVERSION = 0x0000002, VER_MAJORVERSION = 0x0000002,
/// <summary>dwBuildNumber</summary> /// <summary>dwBuildNumber</summary>
VER_BUILDNUMBER = 0x0000004, VER_BUILDNUMBER = 0x0000004,
/// <summary>dwPlatformId</summary> /// <summary>dwPlatformId</summary>
VER_PLATFORMID = 0x0000008, VER_PLATFORMID = 0x0000008,
/// <summary>wServicePackMinor</summary> /// <summary>wServicePackMinor</summary>
VER_SERVICEPACKMINOR = 0x0000010, VER_SERVICEPACKMINOR = 0x0000010,
/// <summary>wServicePackMajor</summary> /// <summary>wServicePackMajor</summary>
VER_SERVICEPACKMAJOR = 0x0000020, VER_SERVICEPACKMAJOR = 0x0000020,
/// <summary>wSuiteMask</summary> /// <summary>wSuiteMask</summary>
VER_SUITENAME = 0x0000040, VER_SUITENAME = 0x0000040,
/// <summary>wProductType</summary> /// <summary>wProductType</summary>
VER_PRODUCT_TYPE = 0x0000080, VER_PRODUCT_TYPE = 0x0000080,
} }
/// <summary> /// <summary>Contains the hardware counter value.</summary>
/// The operator to be used for the comparison. The VerifyVersionInfo function uses this operator to compare a specified attribute value to the // typedef struct _HARDWARE_COUNTER_DATA { HARDWARE_COUNTER_TYPE Type; DWORD Reserved; DWORD64 Value;} HARDWARE_COUNTER_DATA,
/// corresponding value for the currently running system. // *PHARDWARE_COUNTER_DATA; https://msdn.microsoft.com/en-us/library/windows/desktop/dd796394(v=vs.85).aspx
/// </summary> [PInvokeData("Winnt.h", MSDNShortId = "dd796394")]
public enum VERSION_CONDITION : byte [StructLayout(LayoutKind.Sequential)]
public struct HARDWARE_COUNTER_DATA
{ {
/// <summary>The current value must be equal to the specified value.</summary> /// <summary>The type of hardware counter data collected. For possible values, see the <c>HARDWARE_COUNTER_TYPE</c> enumeration.</summary>
VER_EQUAL = 1, public HARDWARE_COUNTER_TYPE Type;
/// <summary>The current value must be greater than the specified value.</summary>
VER_GREATER, /// <summary>Reserved. Initialize to zero.</summary>
/// <summary>The current value must be greater than or equal to the specified value.</summary> public uint Reserved;
VER_GREATER_EQUAL,
/// <summary>The current value must be less than the specified value.</summary> /// <summary>
VER_LESS, /// The counter index. Each hardware counter in a processor's performance monitoring unit (PMU) is identified by an index.
/// <summary>The current value must be less than or equal to the specified value.</summary> /// </summary>
VER_LESS_EQUAL, public ulong Value;
/// <summary>All product suites specified in the wSuiteMask member must be present in the current system.</summary> }
VER_AND,
/// <summary>At least one of the specified product suites must be present in the current system.</summary> /// <summary>Contains the thread profiling and hardware counter data that you requested.</summary>
VER_OR, // typedef struct _PERFORMANCE_DATA { WORD Size; BYTE Version; BYTE HwCountersCount; DWORD ContextSwitchCount; DWORD64
// WaitReasonBitMap; DWORD64 CycleTime; DWORD RetryCount; DWORD Reserved; HARDWARE_COUNTER_DATA HwCounters[MAX_HW_COUNTERS];}
// PERFORMANCE_DATA, *PPERFORMANCE_DATA; https://msdn.microsoft.com/en-us/library/windows/desktop/dd796401(v=vs.85).aspx
[PInvokeData("Winnt.h", MSDNShortId = "dd796401")]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PERFORMANCE_DATA
{
private const int MAX_HW_COUNTERS = 16;
/// <summary>The size of this structure.</summary>
public ushort Size;
/// <summary>The version of this structure. Must be set to PERFORMANCE_DATA_VERSION.</summary>
public byte Version;
/// <summary>
/// The number of array elements in the <c>HwCounters</c> array that contain hardware counter data. A value of 3 means that the
/// array contains data for three hardware counters, not that elements 0 through 2 contain counter data.
/// </summary>
public byte HwCountersCount;
/// <summary>The number of context switches that occurred from the time profiling was enabled.</summary>
public uint ContextSwitchCount;
/// <summary>
/// A bitmask that identifies the reasons for the context switches that occurred since the last time the data was read. For
/// possible values, see the <c>KWAIT_REASON</c> enumeration (the enumeration is included in the Wdm.h file in the WDK).
/// </summary>
public ulong WaitReasonBitMap;
/// <summary>The cycle time of the thread (excludes the time spent interrupted) from the time profiling was enabled.</summary>
public ulong CycleTime;
/// <summary>The number of times that the read operation read the data to ensure a consistent snapshot of the data.</summary>
public uint RetryCount;
/// <summary>Reserved. Set to zero.</summary>
public uint Reserved;
/// <summary>
/// An array of <c>HARDWARE_COUNTER_DATA</c> structures that contain the counter values. The elements of the array that contain
/// counter data relate directly to the bits set in the HardwareCounters bitmask that you specified when you called the
/// <c>EnableThreadProfiling</c> function. For example, if you set bit 3 in the HardwareCounters bitmask, HwCounters[3] will
/// contain the counter data for that counter.
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_HW_COUNTERS)]
public HARDWARE_COUNTER_DATA[] HwCounters;
}
/// <summary>
/// <para>Represents a context frame on WOW64. Refer to the header file WinNT.h for the definition of this structure.</para>
/// </summary>
/// <remarks>
/// <para>
/// In the following versions of Windows, Slot 1 of Thread Local Storage (TLS) holds a pointer to a structure that contains a
/// <c>WOW64_CONTEXT</c> structure starting at offset 4. This might change in later versions of Windows.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Windows Vista</term>
/// <term>Windows Server 2008</term>
/// </listheader>
/// <item>
/// <term>Windows 7</term>
/// <term>Windows Server 2008 R2</term>
/// </item>
/// <item>
/// <term>Windows 8</term>
/// <term>Windows Server 2012</term>
/// </item>
/// <item>
/// <term>Windows 8.1</term>
/// <term>Windows Server 2012 R2</term>
/// </item>
/// </list>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_wow64_context
[PInvokeData("winnt.h", MSDNShortId = "b27205a2-2c33-4f45-8948-9919bcd2355a")]
[StructLayout(LayoutKind.Sequential)]
public struct WOW64_CONTEXT
{
/// <summary/>
public WOW64_CONTEXT_FLAGS ContextFlags;
/// <summary/>
public uint Dr0;
/// <summary/>
public uint Dr1;
/// <summary/>
public uint Dr2;
/// <summary/>
public uint Dr3;
/// <summary/>
public uint Dr6;
/// <summary/>
public uint Dr7;
/// <summary/>
public WOW64_FLOATING_SAVE_AREA FloatSave;
/// <summary/>
public uint SegGs;
/// <summary/>
public uint SegFs;
/// <summary/>
public uint SegEs;
/// <summary/>
public uint SegDs;
/// <summary/>
public uint Edi;
/// <summary/>
public uint Esi;
/// <summary/>
public uint Ebx;
/// <summary/>
public uint Edx;
/// <summary/>
public uint Ecx;
/// <summary/>
public uint Eax;
/// <summary/>
public uint Ebp;
/// <summary/>
public uint Eip;
/// <summary/>
public uint SegCs;
/// <summary/>
public uint EFlags;
/// <summary/>
public uint Esp;
/// <summary/>
public uint SegSs;
/// <summary/>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] ExtendedRegisters;
}
/// <summary>
/// <para>Represents the 80387 save area on WOW64. Refer to the header file WinNT.h for the definition of this structure.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_wow64_floating_save_area
[PInvokeData("winnt.h", MSDNShortId = "56fba1c1-432b-40a8-b882-e4c637c03d5d")]
[StructLayout(LayoutKind.Sequential)]
public struct WOW64_FLOATING_SAVE_AREA
{
/// <summary/>
public uint ControlWord;
/// <summary/>
public uint StatusWord;
/// <summary/>
public uint TagWord;
/// <summary/>
public uint ErrorOffset;
/// <summary/>
public uint ErrorSelector;
/// <summary/>
public uint DataOffset;
/// <summary/>
public uint DataSelector;
/// <summary/>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)]
public byte[] RegisterArea;
/// <summary/>
public uint Cr0NpxState;
}
/// <summary>
/// <para>
/// Describes an entry in the descriptor table for a 32-bit thread on a 64-bit system. This structure is valid only on 64-bit systems.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// The Wow64GetThreadSelectorEntry function fills this structure with information from an entry in the descriptor table. You can use
/// this information to convert a segment-relative address to a linear virtual address.
/// </para>
/// <para>
/// The base address of a segment is the address of offset 0 in the segment. To calculate this value, combine the <c>BaseLow</c>,
/// <c>BaseMid</c>, and <c>BaseHi</c> members.
/// </para>
/// <para>
/// The limit of a segment is the address of the last byte that can be addressed in the segment. To calculate this value, combine the
/// <c>LimitLow</c> and <c>LimitHi</c> members.
/// </para>
/// <para>
/// The <c>WOW64_LDT_ENTRY</c> structure has the same layout for a 64-bit process as the LDT_ENTRY structure has for a 32-bit process.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_wow64_ldt_entry typedef struct _WOW64_LDT_ENTRY { WORD
// LimitLow; WORD BaseLow; union { struct { BYTE BaseMid; BYTE Flags1; BYTE Flags2; BYTE BaseHi; } Bytes; struct { DWORD BaseMid : 8;
// DWORD Type : 5; DWORD Dpl : 2; DWORD Pres : 1; DWORD LimitHi : 4; DWORD Sys : 1; DWORD Reserved_0 : 1; DWORD Default_Big : 1;
// DWORD Granularity : 1; DWORD BaseHi : 8; } Bits; } HighWord; } WOW64_LDT_ENTRY, *PWOW64_LDT_ENTRY;
[PInvokeData("winnt.h", MSDNShortId = "a571cd2f-0873-4ad5-bcb8-c0da2d47a820")]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct WOW64_LDT_ENTRY
{
/// <summary>
/// <para>The low-order part of the address of the last byte in the segment.</para>
/// </summary>
public ushort LimitLow;
/// <summary>
/// <para>The low-order part of the base address of the segment.</para>
/// </summary>
public ushort BaseLow;
/// <summary>
/// <para>Middle bits (16-23) of the base address of the segment.</para>
/// </summary>
public byte BaseMid;
private ushort Flags;
/// <summary>
/// <para>The high bits (24-31) of the base address of the segment.</para>
/// </summary>
public byte BaseHi;
/// <summary>
/// <para>The type of segment. This member can be one of the following values:</para>
/// </summary>
public byte Type { get => (byte)GetBits(Flags, 0, 5); set => SetBits(ref Flags, 0, 5, value); }
/// <summary>
/// <para>
/// The privilege level of the descriptor. This member is an integer value in the range 0 (most privileged) through 3 (least privileged).
/// </para>
/// </summary>
public byte Dpl { get => (byte)GetBits(Flags, 5, 2); set => SetBits(ref Flags, 5, 2, value); }
/// <summary>
/// <para>The present flag. This member is 1 if the segment is present in physical memory or 0 if it is not.</para>
/// </summary>
public bool Pres { get => GetBit(Flags, 7); set => SetBit(ref Flags, 7, value); }
/// <summary>
/// <para>The high bits (16–19) of the address of the last byte in the segment.</para>
/// </summary>
public byte LimitHi { get => (byte)GetBits(Flags, 8, 4); set => SetBits(ref Flags, 8, 4, value); }
/// <summary>
/// <para>
/// The space that is available to system programmers. This member might be used for marking segments in some system-specific way.
/// </para>
/// </summary>
public bool Sys { get => GetBit(Flags, 12); set => SetBit(ref Flags, 12, value); }
/// <summary>
/// <para>Reserved.</para>
/// </summary>
public bool Reserved_0 { get => GetBit(Flags, 13); set => SetBit(ref Flags, 13, value); }
/// <summary>
/// <para>
/// The size of segment. If the segment is a data segment, this member contains 1 if the segment is larger than 64 kilobytes (KB)
/// or 0 if the segment is smaller than or equal to 64 KB.
/// </para>
/// <para>
/// If the segment is a code segment, this member contains 1. The segment runs with the default (native mode) instruction set.
/// </para>
/// </summary>
public bool Default_Big { get => GetBit(Flags, 14); set => SetBit(ref Flags, 14, value); }
/// <summary>
/// <para>The granularity. This member contains 0 if the segment is byte granular, 1 if the segment is page granular.</para>
/// </summary>
public bool Granularity { get => GetBit(Flags, 15); set => SetBit(ref Flags, 15, value); }
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// <summary>
/// <para>Checks whether the user has opted in for SQM data collection as part of the Customer Experience Improvement Program (CEIP).</para>
/// </summary>
/// <returns>
/// <para>True if SQM data collection is opted in and the machine can send data. Otherwise, false.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/windowsceip/nf-windowsceip-ceipisoptedin
// BOOL CeipIsOptedIn( );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("windowsceip.h", MSDNShortId = "4CDB5B09-B172-4E99-AB46-A08E32346266")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CeipIsOptedIn();
}
}