Fixed LOGPALETTE structure and associated functions

pull/382/head
David Hall 2023-02-21 21:33:28 -07:00
parent 30f7fcc941
commit ebbe292a91
6 changed files with 10957 additions and 10889 deletions

View File

@ -1,10 +1,10 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke;
namespace Vanara.PInvoke
{
public static partial class Gdi32
{
/// <summary>
@ -373,9 +373,9 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpalette HPALETTE CreatePalette( const LOGPALETTE
// *plpal );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "f3462198-9360-4b77-ac62-9fe21ec666be")]
public static extern SafeHPALETTE CreatePalette([In] LOGPALETTE plpal);
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
public static extern SafeHPALETTE CreatePalette([In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] LOGPALETTE plpal);
/// <summary>The <c>DeleteColorSpace</c> function removes and destroys a specified color space.</summary>
/// <param name="hcs">Specifies the handle to a color space to delete.</param>
@ -1492,4 +1492,3 @@ namespace Vanara.PInvoke
protected override bool InternalReleaseHandle() => DeleteColorSpace(handle);
}
}
}

View File

@ -1,9 +1,12 @@
using System;
#nullable enable
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
namespace Vanara.PInvoke;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// <summary>
@ -623,6 +626,49 @@ namespace Vanara.PInvoke
[PInvokeData("appmodel.h", MSDNShortId = "D52E98BD-726F-4AC0-A034-02896B1D1687")]
public static extern Win32Error FindPackagesByPackageFamily(string packageFamilyName, PACKAGE_FLAGS packageFilters, ref uint count, IntPtr packageFullNames, ref uint bufferLength, IntPtr buffer, IntPtr packageProperties);
/// <summary>Finds the packages with the specified family name for the current user.</summary>
/// <param name="packageFamilyName"><para>Type: <c>PCWSTR</c></para>
/// <para>The package family name.</para></param>
/// <param name="packageFilters"><para>Type: <c>UINT32</c></para>
/// <para>
/// The package constants that specify how package information is retrieved. All package constants except
/// <c>PACKAGE_FILTER_ALL_LOADED</c> are supported.
/// </para></param>
/// <param name="packageFullNames"><para>Type: <c>PWSTR*</c></para>
/// <para>Receives the strings of package full names that were found.</para></param>
/// <param name="packageProperties"><para>Type: <c>UINT32*</c></para>
/// <para>Receives the package properties for all of the packages that were found.</para></param>
/// <returns>
/// <para>Type: <c>LONG</c></para>
/// <para>
/// If the function succeeds it returns <c>ERROR_SUCCESS</c>. Otherwise, the function returns an error code.
/// </para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-findpackagesbypackagefamily LONG
// FindPackagesByPackageFamily( PCWSTR packageFamilyName, UINT32 packageFilters, UINT32 *count, PWSTR *packageFullNames, UINT32
// *bufferLength, WCHAR *buffer, UINT32 *packageProperties );
[PInvokeData("appmodel.h", MSDNShortId = "D52E98BD-726F-4AC0-A034-02896B1D1687")]
public static Win32Error FindPackagesByPackageFamily(string packageFamilyName, PACKAGE_FLAGS packageFilters, out string?[] packageFullNames, out uint[] packageProperties)
{
uint count = 0, bufferLength = 0;
packageFullNames = new string[0];
packageProperties = new uint[0];
Win32Error err = FindPackagesByPackageFamily(packageFamilyName, packageFilters, ref count, default, ref bufferLength, default, default);
if (count == 0 || err != Win32Error.ERROR_INSUFFICIENT_BUFFER)
return err;
using InteropServices.SafeCoTaskMemHandle mem = new(count * IntPtr.Size + bufferLength * StringHelper.GetCharSize(CharSet.Unicode) + count * sizeof(uint));
IntPtr buffer = mem.DangerousGetHandle().Offset(count * IntPtr.Size);
IntPtr props = mem.DangerousGetHandle().Offset(count * IntPtr.Size + bufferLength * StringHelper.GetCharSize(CharSet.Unicode));
err = FindPackagesByPackageFamily(packageFamilyName, packageFilters, ref count, mem, ref bufferLength, buffer, props);
if (err.Succeeded)
{
packageFullNames = mem.ToStringEnum((int)count, CharSet.Unicode).ToArray();
packageProperties = props.ToArray<uint>((int)count)!;
}
return err;
}
/// <summary>
/// <para>Constructs an application user model ID from the package family name and the package relative application ID (PRAID).</para>
/// </summary>
@ -679,7 +725,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "F48D19C2-6373-41FC-A99D-E3CCB68D6C6C")]
public static extern Win32Error FormatApplicationUserModelId(string packageFamilyName, string packageRelativeApplicationId,
ref uint applicationUserModelIdLength, [Optional] StringBuilder applicationUserModelId);
ref uint applicationUserModelIdLength, [Optional] StringBuilder? applicationUserModelId);
/// <summary>
/// <para>Gets the application user model ID for the specified process.</para>
@ -728,7 +774,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("appmodel.h", MSDNShortId = "FE4E0818-F548-494B-B3BD-FB51DC748451")]
public static extern Win32Error GetApplicationUserModelId(HPROCESS hProcess, ref uint applicationUserModelIdLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder applicationUserModelId);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? applicationUserModelId);
/// <summary>
/// <para>Gets the application user model ID for the specified token.</para>
@ -777,7 +823,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)]
[PInvokeData("appmodel.h", MSDNShortId = "80036518-927E-4CD0-B499-8EA472AB7E5A")]
public static extern Win32Error GetApplicationUserModelIdFromToken(HTOKEN token, ref uint applicationUserModelIdLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder applicationUserModelId);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? applicationUserModelId);
/// <summary>
/// <para>Gets the application user model ID for the current process.</para>
@ -819,7 +865,7 @@ namespace Vanara.PInvoke
// GetCurrentApplicationUserModelId( UINT32 *applicationUserModelIdLength, PWSTR applicationUserModelId );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "562BB225-0922-4FE7-92C0-573A2CCE3195")]
public static extern Win32Error GetCurrentApplicationUserModelId(ref uint applicationUserModelIdLength, [Optional] StringBuilder applicationUserModelId);
public static extern Win32Error GetCurrentApplicationUserModelId(ref uint applicationUserModelIdLength, [Optional] StringBuilder? applicationUserModelId);
/// <summary>
/// <para>Gets the package family name for the calling process.</para>
@ -864,7 +910,7 @@ namespace Vanara.PInvoke
// GetCurrentPackageFamilyName( UINT32 *packageFamilyNameLength, PWSTR packageFamilyName );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "39DBFBDD-A1CC-45C3-A5DD-5ED9697F9AFE")]
public static extern Win32Error GetCurrentPackageFamilyName(ref uint packageFamilyNameLength, [Optional] StringBuilder packageFamilyName);
public static extern Win32Error GetCurrentPackageFamilyName(ref uint packageFamilyNameLength, [Optional] StringBuilder? packageFamilyName);
/// <summary>
/// <para>Gets the package full name for the calling process.</para>
@ -909,7 +955,7 @@ namespace Vanara.PInvoke
// GetCurrentPackageFullName( UINT32 *packageFullNameLength, PWSTR packageFullName );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "D5B00C53-1FBF-4245-92D1-FA39713A9EE7")]
public static extern Win32Error GetCurrentPackageFullName(ref uint packageFullNameLength, [Optional] StringBuilder packageFullName);
public static extern Win32Error GetCurrentPackageFullName(ref uint packageFullNameLength, [Optional] StringBuilder? packageFullName);
/// <summary>
/// <para>Gets the package identifier (ID) for the calling process.</para>
@ -1091,7 +1137,7 @@ namespace Vanara.PInvoke
// *pathLength, PWSTR path );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "46CE81DF-A9D5-492E-AB5E-4F043DC326E2")]
public static extern Win32Error GetCurrentPackagePath(ref uint pathLength, [Optional] StringBuilder path);
public static extern Win32Error GetCurrentPackagePath(ref uint pathLength, [Optional] StringBuilder? path);
/// <summary>
/// Gets the package path for the calling process, with the option to specify the type of folder path to retrieve for the package.
@ -1144,7 +1190,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h")]
public static extern Win32Error GetCurrentPackagePath2(PackagePathType packagePathType, ref uint pathLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder path);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? path);
/// <summary>Returns the package dependency for the specified context handle.</summary>
/// <param name="packageDependencyContext">
@ -1274,7 +1320,7 @@ namespace Vanara.PInvoke
// hProcess, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "AC239898-9924-4193-9072-7A7EEC2D03E9")]
public static extern Win32Error GetPackageFamilyName(HPROCESS hProcess, ref uint packageFamilyNameLength, [Optional] StringBuilder packageFamilyName);
public static extern Win32Error GetPackageFamilyName(HPROCESS hProcess, ref uint packageFamilyNameLength, [Optional] StringBuilder? packageFamilyName);
/// <summary>
/// <para>Gets the package family name for the specified token.</para>
@ -1323,7 +1369,7 @@ namespace Vanara.PInvoke
// GetPackageFamilyNameFromToken( HANDLE token, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName );
[DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "C4FAF5DE-DF1F-4AFA-813B-5D80C786031B")]
public static extern Win32Error GetPackageFamilyNameFromToken(HTOKEN token, ref uint packageFamilyNameLength, [Optional] StringBuilder packageFamilyName);
public static extern Win32Error GetPackageFamilyNameFromToken(HTOKEN token, ref uint packageFamilyNameLength, [Optional] StringBuilder? packageFamilyName);
/// <summary>Gets the package full name for the specified process.</summary>
/// <param name="hProcess">
@ -1377,7 +1423,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h", MSDNShortId = "NF:appmodel.GetPackageFullName")]
public static extern Win32Error GetPackageFullName(HPROCESS hProcess, ref uint packageFullNameLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFullName);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? packageFullName);
/// <summary>
/// <para>Gets the package full name for the specified token.</para>
@ -1422,7 +1468,7 @@ namespace Vanara.PInvoke
// GetPackageFullNameFromToken( HANDLE token, UINT32 *packageFullNameLength, PWSTR packageFullName );
[DllImport(Lib.KernelBase, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "7B0D574E-A2F5-4D08-AEFB-9E040BBC729F")]
public static extern Win32Error GetPackageFullNameFromToken(HTOKEN token, ref uint packageFullNameLength, [Optional] StringBuilder packageFullName);
public static extern Win32Error GetPackageFullNameFromToken(HTOKEN token, ref uint packageFullNameLength, [Optional] StringBuilder? packageFullName);
/// <summary>
/// <para>Gets the package information for the specified package.</para>
@ -1571,7 +1617,7 @@ namespace Vanara.PInvoke
// *packageId, const UINT32 reserved, UINT32 *pathLength, PWSTR path );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "BDA0DD87-A36D-486B-BF89-EA5CC105C742")]
public static extern Win32Error GetPackagePath(in PACKAGE_ID packageId, uint reserved, ref uint pathLength, [Optional] StringBuilder path);
public static extern Win32Error GetPackagePath(in PACKAGE_ID packageId, uint reserved, ref uint pathLength, [Optional] StringBuilder? path);
/// <summary>
/// <para>Gets the path of the specified package.</para>
@ -1615,7 +1661,7 @@ namespace Vanara.PInvoke
// PCWSTR packageFullName, UINT32 *pathLength, PWSTR path );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "9C25708C-1464-4C59-9740-E9F105116385")]
public static extern Win32Error GetPackagePathByFullName(string packageFullName, ref uint pathLength, [Optional] StringBuilder path);
public static extern Win32Error GetPackagePathByFullName(string packageFullName, ref uint pathLength, [Optional] StringBuilder? path);
/// <summary>Gets the path of the specified package, with the option to specify the type of folder path to retrieve for the package.</summary>
/// <param name="packageFullName">
@ -1669,11 +1715,32 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h")]
public static extern Win32Error GetPackagePathByFullName2([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, PackagePathType packagePathType,
ref uint pathLength, [Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder path);
ref uint pathLength, [Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? path);
/// <summary>
/// <para>Gets the packages with the specified family name for the current user.</para>
/// </summary>
/// <summary>Gets the packages with the specified family name for the current user.</summary>
/// <param name="packageFamilyName">The package family name.</param>
/// <param name="packageFullNames">A pointer to the strings of package full names.</param>
/// <returns>If the function succeeds it returns <c>ERROR_SUCCESS</c>. Otherwise, the function returns an error code.</returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagesbypackagefamily LONG
// GetPackagesByPackageFamily( PCWSTR packageFamilyName, UINT32 *count, PWSTR *packageFullNames, UINT32 *bufferLength, WCHAR *buffer );
[PInvokeData("appmodel.h", MSDNShortId = "C2163203-D654-4491-9090-0CC43F42EC35")]
public static Win32Error GetPackagesByPackageFamily(string packageFamilyName, out string?[] packageFullNames)
{
uint count = 0, bufferLength = 0;
packageFullNames = new string[0];
Win32Error err = GetPackagesByPackageFamily(packageFamilyName, ref count, default, ref bufferLength, default);
if (err != Win32Error.ERROR_INSUFFICIENT_BUFFER)
return err;
using InteropServices.SafeCoTaskMemHandle mem = new(count * IntPtr.Size + bufferLength * StringHelper.GetCharSize(CharSet.Unicode));
IntPtr buffer = mem.DangerousGetHandle().Offset(count * IntPtr.Size);
err = GetPackagesByPackageFamily(packageFamilyName, ref count, mem, ref bufferLength, buffer);
if (err.Succeeded)
packageFullNames = mem.ToStringEnum((int)count, CharSet.Unicode).ToArray();
return err;
}
/// <summary>Gets the packages with the specified family name for the current user.</summary>
/// <param name="packageFamilyName">
/// <para>Type: <c>PCWSTR</c></para>
/// <para>The package family name.</para>
@ -1682,8 +1749,8 @@ namespace Vanara.PInvoke
/// <para>Type: <c>UINT32*</c></para>
/// <para>A pointer to a variable that holds the number of package full names.</para>
/// <para>
/// First you pass <c>NULL</c> to packageFullNames to get the number of package full names. You use this number to allocate memory
/// space for packageFullNames. Then you pass the address of this number to fill packageFullNames.
/// First you pass <c>NULL</c> to packageFullNames to get the number of package full names. You use this number to allocate memory space
/// for packageFullNames. Then you pass the address of this number to fill packageFullNames.
/// </para>
/// </param>
/// <param name="packageFullNames">
@ -1694,8 +1761,8 @@ namespace Vanara.PInvoke
/// <para>Type: <c>UINT32*</c></para>
/// <para>A pointer to a variable that holds the number of characters in the string of package full names.</para>
/// <para>
/// First you pass <c>NULL</c> to buffer to get the number of characters. You use this number to allocate memory space for buffer.
/// Then you pass the address of this number to fill buffer.
/// First you pass <c>NULL</c> to buffer to get the number of characters. You use this number to allocate memory space for buffer. Then
/// you pass the address of this number to fill buffer.
/// </para>
/// </param>
/// <param name="buffer">
@ -1705,8 +1772,8 @@ namespace Vanara.PInvoke
/// <returns>
/// <para>Type: <c>LONG</c></para>
/// <para>
/// If the function succeeds it returns <c>ERROR_SUCCESS</c>. Otherwise, the function returns an error code. The possible error
/// codes include the following.
/// If the function succeeds it returns <c>ERROR_SUCCESS</c>. Otherwise, the function returns an error code. The possible error codes
/// include the following.
/// </para>
/// <list type="table">
/// <listheader>
@ -1723,7 +1790,8 @@ namespace Vanara.PInvoke
// GetPackagesByPackageFamily( PCWSTR packageFamilyName, UINT32 *count, PWSTR *packageFullNames, UINT32 *bufferLength, WCHAR *buffer );
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "C2163203-D654-4491-9090-0CC43F42EC35")]
public static extern Win32Error GetPackagesByPackageFamily(string packageFamilyName, ref uint count, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] packageFullNames, ref uint bufferLength, IntPtr buffer);
public static extern Win32Error GetPackagesByPackageFamily(string packageFamilyName, ref uint count,
[Out] IntPtr packageFullNames, ref uint bufferLength, [Out] IntPtr buffer);
/// <summary>
/// <para>Gets the origin of the specified package.</para>
@ -1810,7 +1878,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h", MSDNShortId = "F0A37D77-6262-44B1-BEC5-083E41BDE139")]
public static extern Win32Error GetStagedPackagePathByFullName([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, ref uint pathLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder path);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? path);
/// <summary>
/// Gets the path of the specified staged package, with the option to specify the type of folder path to retrieve for the package.
@ -1866,7 +1934,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h")]
public static extern Win32Error GetStagedPackagePathByFullName2([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, PackagePathType packagePathType,
ref uint pathLength, [Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder path);
ref uint pathLength, [Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? path);
/// <summary>
/// <para>Opens the package information of the specified package.</para>
@ -1950,7 +2018,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "98E95CE5-E970-4A19-BAD3-994DAEC4BEA0")]
public static extern Win32Error PackageFamilyNameFromFullName(string packageFullName, ref uint packageFamilyNameLength,
[Optional] StringBuilder packageFamilyName);
[Optional] StringBuilder? packageFamilyName);
/// <summary>
/// <para>Gets the package family name for the specified package identifier.</para>
@ -1996,7 +2064,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h", MSDNShortId = "198DAB6B-21D2-4ACB-87DF-B3F4EFBEE323")]
public static extern Win32Error PackageFamilyNameFromId(in PACKAGE_ID packageId, ref uint packageFamilyNameLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFamilyName);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? packageFamilyName);
/// <summary>
/// <para>Gets the package full name for the specified package identifier (ID).</para>
@ -2042,7 +2110,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("appmodel.h", MSDNShortId = "0024AF55-295E-49B1-90C2-9144D336529B")]
public static extern Win32Error PackageFullNameFromId(in PACKAGE_ID packageId, ref uint packageFullNameLength,
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFullName);
[Optional, MarshalAs(UnmanagedType.LPWStr)] StringBuilder? packageFullName);
/// <summary>
/// <para>Gets the package identifier (ID) for the specified package full name.</para>
@ -2194,7 +2262,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "4AA5BD75-F865-40D6-9C10-E54C197D47C4")]
public static extern Win32Error PackageNameAndPublisherIdFromFamilyName(string packageFamilyName, ref uint packageNameLength,
[Optional] StringBuilder packageName, ref uint packagePublisherIdLength, [Optional] StringBuilder packagePublisherId);
[Optional] StringBuilder? packageName, ref uint packagePublisherIdLength, [Optional] StringBuilder? packagePublisherId);
/// <summary>
/// <para>Deconstructs an application user model ID to its package family name and package relative application ID (PRAID).</para>
@ -2263,7 +2331,7 @@ namespace Vanara.PInvoke
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("appmodel.h", MSDNShortId = "03B29E82-611F-47D1-8CB6-047B9BEB4D9E")]
public static extern Win32Error ParseApplicationUserModelId(string applicationUserModelId, ref uint packageFamilyNameLength,
[Optional] StringBuilder packageFamilyName, ref uint packageRelativeApplicationIdLength, [Optional] StringBuilder packageRelativeApplicationId);
[Optional] StringBuilder? packageFamilyName, ref uint packageRelativeApplicationIdLength, [Optional] StringBuilder? packageRelativeApplicationId);
/// <summary>
/// Removes a resolved package dependency from the current process' package graph (that is, a run-time reference for a framework
@ -2542,7 +2610,7 @@ namespace Vanara.PInvoke
public static bool operator ==(PACKAGEDEPENDENCY_CONTEXT h1, PACKAGEDEPENDENCY_CONTEXT h2) => h1.Equals(h2);
/// <inheritdoc/>
public override bool Equals(object obj) => obj is PACKAGEDEPENDENCY_CONTEXT h && handle == h.handle;
public override bool Equals(object? obj) => obj is PACKAGEDEPENDENCY_CONTEXT h && handle == h.handle;
/// <inheritdoc/>
public override int GetHashCode() => handle.GetHashCode();
@ -2551,4 +2619,3 @@ namespace Vanara.PInvoke
public IntPtr DangerousGetHandle() => handle;
}
}
}

View File

@ -8289,7 +8289,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-iviewobject-getcolorset HRESULT GetColorSet( DWORD
// dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet );
new unsafe HRESULT GetColorSet(DVASPECT dwDrawAspect, int lindex, [In, Optional] DVASPECTINFO* pvAspect, [In, Optional] DVTARGETDEVICE* ptd,
[In, Optional] HDC hicTargetDev, out LOGPALETTE ppColorSet);
[In, Optional] HDC hicTargetDev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] out LOGPALETTE ppColorSet);
/// <summary>
/// Freezes the drawn representation of an object so that it will not change until the IViewObject::Unfreeze method is called.

View File

@ -2,9 +2,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Vanara.InteropServices;
namespace Vanara.PInvoke;
namespace Vanara.PInvoke
{
public static partial class Ole32
{
/// <summary>Specifies what to do with caches that are to be discarded from memory if their dirty bit has been set.</summary>
@ -5685,7 +5686,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-ioleobject-setcolorscheme HRESULT SetColorScheme(
// LOGPALETTE *pLogpal );
[PreserveSig]
HRESULT SetColorScheme(IntPtr pLogpal);
HRESULT SetColorScheme([In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] LOGPALETTE pLogpal);
}
/// <summary>
@ -6208,7 +6209,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-iviewobject-getcolorset HRESULT GetColorSet( DWORD
// dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet );
unsafe HRESULT GetColorSet(DVASPECT dwDrawAspect, int lindex, [In, Optional] DVASPECTINFO* pvAspect, [In, Optional] DVTARGETDEVICE* ptd,
[In, Optional] HDC hicTargetDev, out LOGPALETTE ppColorSet);
[In, Optional] HDC hicTargetDev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] out LOGPALETTE ppColorSet);
/// <summary>
/// Freezes the drawn representation of an object so that it will not change until the IViewObject::Unfreeze method is called.
@ -6658,7 +6659,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-iviewobject-getcolorset HRESULT GetColorSet( DWORD
// dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet );
new unsafe HRESULT GetColorSet(DVASPECT dwDrawAspect, int lindex, [In, Optional] DVASPECTINFO* pvAspect, [In, Optional] DVTARGETDEVICE* ptd,
[In, Optional] HDC hicTargetDev, out LOGPALETTE ppColorSet);
[In, Optional] HDC hicTargetDev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] out LOGPALETTE ppColorSet);
/// <summary>
/// Freezes the drawn representation of an object so that it will not change until the IViewObject::Unfreeze method is called.
@ -6970,4 +6971,3 @@ namespace Vanara.PInvoke
public OLEVERBATTRIB grfAttribs;
}
}
}

View File

@ -1,9 +1,11 @@
using System;
#nullable enable
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke;
namespace Vanara.PInvoke
{
/// <summary>The alpha intensity value for the palette entry.</summary>
[PInvokeData("wingdi.h")]
[Flags]
@ -38,8 +40,9 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogpalette typedef struct tagLOGPALETTE { WORD
// palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, *PLOGPALETTE, *NPLOGPALETTE, *LPLOGPALETTE;
[PInvokeData("wingdi.h", MSDNShortId = "99d70a0e-ac61-4a88-a500-66443e7882ad")]
[VanaraMarshaler(typeof(SafeAnysizeStructMarshaler<LOGPALETTE>), nameof(palNumEntries))]
[StructLayout(LayoutKind.Sequential)]
public class LOGPALETTE : IDisposable
public class LOGPALETTE
{
/// <summary>The version number of the system.</summary>
public ushort palVersion;
@ -47,17 +50,9 @@ namespace Vanara.PInvoke
/// <summary>The number of entries in the logical palette.</summary>
public ushort palNumEntries;
private IntPtr _palPalEntry;
/// <summary>Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette.</summary>
public PALETTEENTRY[] palPalEntry
{
get => _palPalEntry.ToArray<PALETTEENTRY>(palNumEntries);
set { Marshal.FreeHGlobal(_palPalEntry); value.MarshalToPtr<PALETTEENTRY>(Marshal.AllocHGlobal, out _); }
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
void IDisposable.Dispose() => Marshal.FreeHGlobal(_palPalEntry);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public PALETTEENTRY[]? palPalEntry;
}
/// <summary>Specifies the color and usage of an entry in a logical palette.</summary>
@ -94,4 +89,3 @@ namespace Vanara.PInvoke
/// </summary>
public PC peFlags;
}
}

View File

@ -34,6 +34,14 @@ namespace Vanara.PInvoke.Tests
Assert.That(CreateFont(), ResultIs.ValidHandle);
}
[Test]
public void CreatePaletteTest()
{
LOGPALETTE lp = new() { palVersion = 0x300, palNumEntries = 32, palPalEntry = new PALETTEENTRY[32] };
for (int i = 0;i < 32; i++) { lp.palPalEntry[i] = new() { peFlags = PC.PC_NOCOLLAPSE }; }
Assert.That(CreatePalette(lp), ResultIs.ValidHandle);
}
// TODO: [Test]
public void DeleteDCTest()
{