From 79ceb6112ec18b19fa2150e107cb8f8f36bb6c7f Mon Sep 17 00:00:00 2001 From: dahall Date: Wed, 23 Dec 2020 12:14:55 -0700 Subject: [PATCH] More work on WTSApi32 --- PInvoke/WTSApi32/WTSApi32.cs | 6 ++ PInvoke/WTSApi32/WTSHintApi.cs | 93 +++++++++++++++++++++++++++++ UnitTests/PInvoke/WTSApi32/WTSApi32.csproj | 8 +++ UnitTests/PInvoke/WTSApi32/WTSApi32Tests.cs | 29 +++++++++ 4 files changed, 136 insertions(+) create mode 100644 PInvoke/WTSApi32/WTSHintApi.cs create mode 100644 UnitTests/PInvoke/WTSApi32/WTSApi32.csproj create mode 100644 UnitTests/PInvoke/WTSApi32/WTSApi32Tests.cs diff --git a/PInvoke/WTSApi32/WTSApi32.cs b/PInvoke/WTSApi32/WTSApi32.cs index ba0fcc7c..8ecbc47d 100644 --- a/PInvoke/WTSApi32/WTSApi32.cs +++ b/PInvoke/WTSApi32/WTSApi32.cs @@ -3700,6 +3700,12 @@ namespace Vanara.PInvoke /// A that represents this instance. public string ToString(uint allocatedBytes) => StringHelper.GetString(handle, CharSet.Auto, allocatedBytes); + /// Marshals data from this memory to a newly allocated managed object of the type specified by a generic type parameter. + /// The type of the object to which the data is to be copied. This must be a structure. + /// If known, the total number of bytes allocated to the native memory in . + /// A managed object that contains the data that this memory points to. + public T ToStructure(uint allocatedBytes) => handle.Convert(allocatedBytes == 0 ? uint.MaxValue : allocatedBytes); + #if ALLOWSPAN /// Creates a new span over this allocated memory. /// The span representation of the structure. diff --git a/PInvoke/WTSApi32/WTSHintApi.cs b/PInvoke/WTSApi32/WTSHintApi.cs new file mode 100644 index 00000000..6c21cfdd --- /dev/null +++ b/PInvoke/WTSApi32/WTSHintApi.cs @@ -0,0 +1,93 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + /// Items from the WTSApi32.dll + public static partial class WTSApi32 + { + /// Specifies the type of hint represented by a call to . + [PInvokeData("wtshintapi.h", MSDNShortId = "NF:wtshintapi.WTSSetRenderHint")] + public enum RENDER_HINT + { + /// + /// The previous hint is cleared. + /// pHintData must be NULL. + /// + RENDER_HINT_CLEAR = 0x0, + + /// + /// Indicates the presence of moving video. + /// + /// pHintData contains a RECT structure which specifies the coordinates and size of the rendering area. These per-monitor + /// DPI-aware coordinates are relative to the client coordinates of the window represented by the hwndOwner parameter. + /// + /// + RENDER_HINT_VIDEO = 0x1, + + /// + /// Indicates the presence of a window mapping. + /// + /// pHintData contains a RECT structure which specifies the coordinates and size of the rendering area. These per-monitor + /// DPI-aware coordinates are relative to the client coordinates of the window represented by the hwndOwner parameter. + /// + /// + /// Windows 8 and Windows Server 2012: The coordinates are not DPI-aware before Windows 8.1 and Windows Server 2012 R2. + /// + /// + RENDER_HINT_MAPPEDWINDOW = 0x2, + } + + /// + /// + /// Used by an application that is displaying content that can be optimized for displaying in a remote session to identify the + /// region of a window that is the actual content. + /// + /// In the remote session, this content will be encoded, sent to the client, then decoded and displayed. + /// + /// + /// The address of a value that identifies the rendering hint affected by this call. If a new hint is being created, this value must + /// contain zero. This function will return a unique rendering hint identifier which is used for subsequent calls, such as clearing + /// the hint. + /// + /// + /// The handle of window linked to lifetime of the rendering hint. This window is used in situations where a hint target is removed + /// without the hint being explicitly cleared. + /// + /// + /// Specifies the type of hint represented by this call. + /// RENDER_HINT_CLEAR (0) + /// The previous hint is cleared. + /// pHintData must be NULL. + /// RENDER_HINT_VIDEO (1) + /// Indicates the presence of moving video. + /// + /// pHintData contains a RECT structure which specifies the coordinates and size of the rendering area. These per-monitor DPI-aware + /// coordinates are relative to the client coordinates of the window represented by the hwndOwner parameter. + /// + /// + /// Windows 8 and Windows Server 2012: The coordinates are not DPI-aware before Windows 8.1 and Windows Server 2012 R2. + /// + /// RENDER_HINT_MAPPEDWINDOW (2) + /// Indicates the presence of a window mapping. + /// + /// pHintData contains a RECT structure which specifies the coordinates and size of the rendering area. These per-monitor DPI-aware + /// coordinates are relative to the client coordinates of the window represented by the hwndOwner parameter. + /// + /// + /// Windows 8 and Windows Server 2012: The coordinates are not DPI-aware before Windows 8.1 and Windows Server 2012 R2. + /// + /// + /// The size, in BYTE s, of the pHintData buffer. + /// + /// Additional data for the hint. + /// The format of this data is dependent upon the value passed in the renderHintType parameter. + /// + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + // https://docs.microsoft.com/en-us/windows/win32/api/wtshintapi/nf-wtshintapi-wtssetrenderhint HRESULT WTSSetRenderHint( UINT64 + // *pRenderHintID, HWND hwndOwner, DWORD renderHintType, DWORD cbHintDataLength, BYTE *pHintData ); + [DllImport(Lib_WTSApi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wtshintapi.h", MSDNShortId = "NF:wtshintapi.WTSSetRenderHint")] + public static extern HRESULT WTSSetRenderHint(ref ulong pRenderHintID, HWND hwndOwner, RENDER_HINT renderHintType, uint cbHintDataLength, [In, Optional] IntPtr pHintData); + } +} \ No newline at end of file diff --git a/UnitTests/PInvoke/WTSApi32/WTSApi32.csproj b/UnitTests/PInvoke/WTSApi32/WTSApi32.csproj new file mode 100644 index 00000000..81695599 --- /dev/null +++ b/UnitTests/PInvoke/WTSApi32/WTSApi32.csproj @@ -0,0 +1,8 @@ + + + UnitTest.PInvoke.WTSApi32 + + + + + \ No newline at end of file diff --git a/UnitTests/PInvoke/WTSApi32/WTSApi32Tests.cs b/UnitTests/PInvoke/WTSApi32/WTSApi32Tests.cs new file mode 100644 index 00000000..ae43c47f --- /dev/null +++ b/UnitTests/PInvoke/WTSApi32/WTSApi32Tests.cs @@ -0,0 +1,29 @@ +using NUnit.Framework; +using NUnit.Framework.Internal; +using System; +using System.Runtime.InteropServices; +using static Vanara.PInvoke.WTSApi32; + +namespace Vanara.PInvoke.Tests +{ + [TestFixture] + public class WTSApi32Tests + { + [OneTimeSetUp] + public void _Setup() + { + } + + [OneTimeTearDown] + public void _TearDown() + { + } + + [Test] + public void WTSEnumerateServersTest() + { + Assert.That(WTSEnumerateServers(null, out var servers), ResultIs.Successful); + servers.WriteValues(); + } + } +} \ No newline at end of file