Updates to hopefully fix PInvoke.Shared load problems

pull/299/head
dahall 2022-04-22 13:24:51 -06:00
parent 76722fbcf5
commit 013ee74453
3 changed files with 52 additions and 9 deletions

View File

@ -30,7 +30,7 @@ CharacterSet, CM_DEVCAP, CM_FILE, CM_INSTALL_STATE, CM_REMOVAL_POLICY, CM_RESOUR
<ItemGroup>
<ProjectReference Include="..\..\Core\Vanara.Core.csproj" />
</ItemGroup>
<ItemGroup Condition=" !$(TargetFramework.StartsWith('net4')) ">
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcore')) Or $(TargetFramework.StartsWith('net5.0')) Or $(TargetFramework.StartsWith('net6.0')) ">
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
</ItemGroup>
</Project>

View File

@ -8,7 +8,7 @@ namespace Vanara.PInvoke
// typedef DWORD COLORREF;typedef DWORD* LPCOLORREF; https://msdn.microsoft.com/en-us/library/windows/desktop/dd183449(v=vs.85).aspx
[PInvokeData("Windef.h", MSDNShortId = "dd183449")]
[StructLayout(LayoutKind.Explicit, Size = 4)]
public struct COLORREF
public struct COLORREF : IEquatable<COLORREF>
{
/// <summary>The DWORD value</summary>
[FieldOffset(0)]
@ -81,6 +81,17 @@ namespace Vanara.PInvoke
byte Conv(byte c) => (byte)(c - (int)(c * percent));
}
/// <inheritdoc/>
public override bool Equals(object obj) => obj is COLORREF q && Equals(q);
/// <summary>Determines whether the specified object is equal to the current object.</summary>
/// <param name="c">The object to compare with the current object.</param>
/// <returns><see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>.</returns>
public bool Equals(COLORREF c) => c.A == A && c.B == B && c.G == G && c.R == R;
/// <inheritdoc/>
public override int GetHashCode() => ToArgb();
/// <summary>A method to lighten a color by a percentage of the difference between the color and Black.</summary>
/// <param name="percent">The percentage by which to lighten the original color.</param>
/// <returns>

View File

@ -1,11 +1,12 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// <summary>The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue.</summary>
[StructLayout(LayoutKind.Sequential)]
[PInvokeData("Wingdi.h", MSDNShortId = "dd162938")]
public struct RGBQUAD
[StructLayout(LayoutKind.Sequential, Size = 4)]
public struct RGBQUAD : IEquatable<RGBQUAD>
{
/// <summary>The intensity of blue in the color.</summary>
public byte rgbBlue;
@ -19,6 +20,18 @@ namespace Vanara.PInvoke
/// <summary>This member is reserved and must be zero.</summary>
public byte rgbReserved;
/// <summary>Initializes a new instance of the <see cref="RGBQUAD"/> struct.</summary>
/// <param name="r">The intensity of the red color.</param>
/// <param name="g">The intensity of the green color.</param>
/// <param name="b">The intensity of the blue color.</param>
public RGBQUAD(byte r, byte g, byte b)
{
rgbRed = r;
rgbGreen = g;
rgbBlue = b;
rgbReserved = 0;
}
/// <summary>Gets a value indicating whether any transparency is defined.</summary>
/// <value><see langword="true"/> if this value is transparent; otherwise, <see langword="false"/>.</value>
public bool IsTransparent => rgbReserved == 0;
@ -31,23 +44,42 @@ namespace Vanara.PInvoke
set { rgbReserved = value.A; rgbBlue = value.B; rgbGreen = value.G; rgbRed = value.R; }
}
/// <inheritdoc/>
public override bool Equals(object obj) => obj is RGBQUAD q && Equals(q);
/// <summary>Determines whether the specified object is equal to the current object.</summary>
/// <param name="q">The object to compare with the current object.</param>
/// <returns><see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>.</returns>
public bool Equals(RGBQUAD q) => q.rgbBlue == rgbBlue && q.rgbGreen == rgbGreen && q.rgbRed == rgbRed && q.rgbReserved == rgbReserved;
/// <inheritdoc/>
public override int GetHashCode() => unchecked((int)(uint)this);
/// <inheritdoc/>
public override string ToString() => $"{{R={rgbRed},G={rgbGreen},B={rgbBlue}}}";
/// <summary>Performs an implicit conversion from <see cref="RGBQUAD"/> to <see cref="uint"/>.</summary>
/// <param name="c">The <see cref="RGBQUAD"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator uint(RGBQUAD c) { unsafe { return *(uint*)&c; } }
/// <summary>Performs an implicit conversion from <see cref="COLORREF"/> to <see cref="RGBQUAD"/>.</summary>
/// <param name="c">The c.</param>
/// <param name="c">The <see cref="COLORREF"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator RGBQUAD(COLORREF c) => new() { Color = c };
/// <summary>Performs an implicit conversion from <see cref="RGBQUAD"/> to <see cref="COLORREF"/>.</summary>
/// <param name="c">The c.</param>
/// <param name="c">The <see cref="RGBQUAD"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator COLORREF(RGBQUAD c) => c.Color;
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Color"/> to <see cref="RGBQUAD"/>.</summary>
/// <param name="c">The c.</param>
/// <param name="c">The <see cref="System.Drawing.Color"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator RGBQUAD(System.Drawing.Color c) => new() { Color = c };
/// <summary>Performs an implicit conversion from <see cref="RGBQUAD"/> to <see cref="System.Drawing.Color"/>.</summary>
/// <param name="c">The c.</param>
/// <param name="c">The <see cref="RGBQUAD"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator System.Drawing.Color(RGBQUAD c) => c.Color;
}