From 5bd89799d129cb5a9dfd458d3658215b8dce4c2c Mon Sep 17 00:00:00 2001 From: Shmueli Englard Date: Fri, 15 Dec 2023 23:32:37 -0800 Subject: [PATCH] Migrated to use CsWin32 --- .../BaseActivationFactory.cs | 7 +- src/Shmuelie.WinRTServer/BaseClassFactory.cs | 1 - src/Shmuelie.WinRTServer/ComServer.cs | 12 +- .../Internal/BaseActivationFactoryProxy.cs | 70 +++--- .../Internal/BaseClassFactoryProxy.cs | 46 ++-- src/Shmuelie.WinRTServer/NativeMethods.json | 8 + src/Shmuelie.WinRTServer/NativeMethods.txt | 24 +++ .../Shmuelie.WinRTServer.csproj | 5 +- src/Shmuelie.WinRTServer/WinRtServer.cs | 50 +++-- .../WinRtServerExtensions.cs | 3 + .../Windows/Win32/PInvoke.cs | 8 + .../Windows/shared/uuids/__uuidof.cs | 6 +- .../Windows/shared/winerror/E.cs | 27 --- .../Windows/shared/winerror/S.cs | 17 -- .../Windows/shared/winerror/WinError.cs | 9 - .../Windows/shared/wtypesbase/CLSCTX.cs | 18 -- .../Windows/um/Unknwnbase/IClassFactory.cs | 82 ------- .../Windows/um/Unknwnbase/IUnknown.cs | 54 ----- .../Windows/um/combaseapi/ComBaseAPI.cs | 203 ------------------ .../Windows/um/combaseapi/REGCLS.cs | 31 --- .../um/objidlbase/GLOBALOPT_PROPERTIES.cs | 13 -- .../um/objidlbase/GLOBALOPT_RO_FLAGS.cs | 12 -- .../Windows/um/objidlbase/IGlobalOptions.cs | 67 ------ .../Windows/winrt/HSTRING.cs | 113 ---------- .../winrt/activation/IActivationFactory.cs | 94 -------- .../Windows/winrt/inspectable/IInspectable.cs | 108 ---------- .../Windows/winrt/inspectable/TrustLevel.cs | 13 -- .../winrt/roapi/DllGetActivationFactory.cs | 45 ---- .../Windows/winrt/roapi/RO_INIT_TYPE.cs | 13 -- .../winrt/roapi/RO_REGISTRATION_COOKIE.cs | 109 ---------- .../Windows/winrt/roapi/RoAPI.cs | 124 ----------- .../Windows/winrt/winstring/WinString.cs | 146 ------------- .../Windows/winrt/wrl/client/ComPtr.cs | 44 ++-- 33 files changed, 181 insertions(+), 1401 deletions(-) create mode 100644 src/Shmuelie.WinRTServer/NativeMethods.json create mode 100644 src/Shmuelie.WinRTServer/NativeMethods.txt create mode 100644 src/Shmuelie.WinRTServer/Windows/Win32/PInvoke.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/shared/winerror/E.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/shared/winerror/S.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/shared/winerror/WinError.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/shared/wtypesbase/CLSCTX.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IClassFactory.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IUnknown.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/combaseapi/ComBaseAPI.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/combaseapi/REGCLS.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_PROPERTIES.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_RO_FLAGS.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/um/objidlbase/IGlobalOptions.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/HSTRING.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/activation/IActivationFactory.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/inspectable/IInspectable.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/inspectable/TrustLevel.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/roapi/DllGetActivationFactory.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_INIT_TYPE.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_REGISTRATION_COOKIE.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/roapi/RoAPI.cs delete mode 100644 src/Shmuelie.WinRTServer/Windows/winrt/winstring/WinString.cs diff --git a/src/Shmuelie.WinRTServer/BaseActivationFactory.cs b/src/Shmuelie.WinRTServer/BaseActivationFactory.cs index b75c9f0..021a5e9 100644 --- a/src/Shmuelie.WinRTServer/BaseActivationFactory.cs +++ b/src/Shmuelie.WinRTServer/BaseActivationFactory.cs @@ -1,13 +1,14 @@ using System; -using System.Runtime.InteropServices.WindowsRuntime; namespace Shmuelie.WinRTServer; /// /// Base for a WinRT Activation Factory for a .NET type. /// -/// -public abstract class BaseActivationFactory : IActivationFactory +#if !NETSTANDARD +[System.Runtime.Versioning.SupportedOSPlatform("windows8.0")] +#endif +public abstract class BaseActivationFactory { /// public abstract object ActivateInstance(); diff --git a/src/Shmuelie.WinRTServer/BaseClassFactory.cs b/src/Shmuelie.WinRTServer/BaseClassFactory.cs index aaa25ce..b115404 100644 --- a/src/Shmuelie.WinRTServer/BaseClassFactory.cs +++ b/src/Shmuelie.WinRTServer/BaseClassFactory.cs @@ -5,7 +5,6 @@ namespace Shmuelie.WinRTServer; /// /// Base for a COM class factory for a .NET type. /// -/// /// Does not support aggregation. Will always return CLASS_E_NOAGGREGATION if requested. public abstract class BaseClassFactory { diff --git a/src/Shmuelie.WinRTServer/ComServer.cs b/src/Shmuelie.WinRTServer/ComServer.cs index 0a3ce1a..a603670 100644 --- a/src/Shmuelie.WinRTServer/ComServer.cs +++ b/src/Shmuelie.WinRTServer/ComServer.cs @@ -4,8 +4,9 @@ using System.Threading.Tasks; using System.Timers; using Shmuelie.Interop.Windows; -using static Shmuelie.Interop.Windows.ComBaseAPI; -using static Shmuelie.Interop.Windows.Windows; +using Windows.Win32.Foundation; +using Windows.Win32.System.Com; +using static Windows.Win32.PInvoke; namespace Shmuelie.WinRTServer; @@ -42,8 +43,9 @@ public sealed class ComServer : IAsyncDisposable public unsafe ComServer() { using ComPtr options = default; - Guid clsid = IGlobalOptions.CLSID; - if (CoCreateInstance(&clsid, null, (uint)CLSCTX.CLSCTX_INPROC_SERVER, __uuidof(), (void**)options.GetAddressOf()) == S.S_OK) + Guid clsid = CLSID_GlobalOptions; + Guid iid = IGlobalOptions.IID_Guid; + if (CoCreateInstance(&clsid, null, CLSCTX.CLSCTX_INPROC_SERVER, &iid, (void**)options.GetAddressOf()) == HRESULT.S_OK) { options.Get()->Set(GLOBALOPT_PROPERTIES.COMGLB_RO_SETTINGS, (nuint)GLOBALOPT_RO_FLAGS.COMGLB_FAST_RUNDOWN); } @@ -128,7 +130,7 @@ public unsafe bool RegisterClassFactory(BaseClassFactory factory) proxy.Attach(BaseClassFactoryProxy.Create(factory)); uint cookie; - Marshal.ThrowExceptionForHR(CoRegisterClassObject(&clsid, (IUnknown*)proxy.Get(), (uint)CLSCTX.CLSCTX_LOCAL_SERVER, (uint)(REGCLS.REGCLS_MULTIPLEUSE | REGCLS.REGCLS_SUSPENDED), &cookie)); + Marshal.ThrowExceptionForHR(CoRegisterClassObject(&clsid, (IUnknown*)proxy.Get(), CLSCTX.CLSCTX_LOCAL_SERVER, (REGCLS.REGCLS_MULTIPLEUSE | REGCLS.REGCLS_SUSPENDED), &cookie)); factories.Add(clsid, (factory, cookie)); return true; diff --git a/src/Shmuelie.WinRTServer/Internal/BaseActivationFactoryProxy.cs b/src/Shmuelie.WinRTServer/Internal/BaseActivationFactoryProxy.cs index d55dd20..e9b38a2 100644 --- a/src/Shmuelie.WinRTServer/Internal/BaseActivationFactoryProxy.cs +++ b/src/Shmuelie.WinRTServer/Internal/BaseActivationFactoryProxy.cs @@ -2,14 +2,20 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; +using Windows.Win32.System.WinRT; +using Windows.Win32.System.Com; +using Windows.Win32.Foundation; +using static Windows.Win32.PInvoke; using Shmuelie.Interop.Windows; -using static Shmuelie.Interop.Windows.Windows; namespace Shmuelie.WinRTServer; /// /// CCW for . /// +#if !NETSTANDARD +[System.Runtime.Versioning.SupportedOSPlatform("windows8.0")] +#endif internal unsafe struct BaseActivationFactoryProxy { private static readonly void** Vtbl = InitVtbl(); @@ -64,7 +70,7 @@ public uint Release() private static class Impl { [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int QueryInterfaceDelegate(BaseActivationFactoryProxy* @this, Guid* riid, void** ppvObject); + public delegate HRESULT QueryInterfaceDelegate(BaseActivationFactoryProxy* @this, Guid* riid, void** ppvObject); [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate uint AddRefDelegate(BaseActivationFactoryProxy* @this); @@ -73,16 +79,16 @@ private static class Impl public delegate uint ReleaseDelegate(BaseActivationFactoryProxy* @this); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int GetIidsDelegate(BaseActivationFactoryProxy* @this, uint* iidCount, Guid** iids); + public delegate HRESULT GetIidsDelegate(BaseActivationFactoryProxy* @this, uint* iidCount, Guid** iids); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int GetRuntimeClassNameDelegate(BaseActivationFactoryProxy* @this, HSTRING* className); + public delegate HRESULT GetRuntimeClassNameDelegate(BaseActivationFactoryProxy* @this, HSTRING* className); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int GetTrustLevelDelegate(BaseActivationFactoryProxy* @this, TrustLevel* trustLevel); + public delegate HRESULT GetTrustLevelDelegate(BaseActivationFactoryProxy* @this, TrustLevel* trustLevel); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int ActivateInstanceDelegate(BaseActivationFactoryProxy* @this, IInspectable** instance); + public delegate HRESULT ActivateInstanceDelegate(BaseActivationFactoryProxy* @this, IInspectable** instance); /// /// The cached for IUnknown.QueryInterface(REFIID, void**). @@ -110,20 +116,20 @@ private static class Impl /// /// Implements IUnknown.QueryInterface(REFIID, void**). /// - private static int QueryInterface(BaseActivationFactoryProxy* @this, Guid* riid, void** ppvObject) + private static HRESULT QueryInterface(BaseActivationFactoryProxy* @this, Guid* riid, void** ppvObject) { - if (riid->Equals(__uuidof()) || - riid->Equals(__uuidof()) || - riid->Equals(__uuidof())) + if (riid->Equals(IUnknown.IID_Guid) || + riid->Equals(IInspectable.IID_Guid) || + riid->Equals(IActivationFactory.IID_Guid)) { _ = Interlocked.Increment(ref Unsafe.As(ref @this->_referenceCount)); *ppvObject = @this; - return S.S_OK; + return HRESULT.S_OK; } - return E.E_NOINTERFACE; + return HRESULT.E_NOINTERFACE; } /// @@ -151,99 +157,99 @@ public static uint Release(BaseActivationFactoryProxy* @this) return referenceCount; } - public static int GetIids(BaseActivationFactoryProxy* @this, uint* iidCount, Guid** iids) + public static HRESULT GetIids(BaseActivationFactoryProxy* @this, uint* iidCount, Guid** iids) { if (iidCount is null || iids is null) { - return E.E_INVALIDARG; + return HRESULT.E_INVALIDARG; } *iidCount = 1; *iids = (Guid*)Marshal.AllocHGlobal(sizeof(Guid)); - *iids[0] = __uuidof(); - return S.S_OK; + *iids[0] = IActivationFactory.IID_Guid; + return HRESULT.S_OK; } - public static int GetRuntimeClassName(BaseActivationFactoryProxy* @this, HSTRING* className) + public static HRESULT GetRuntimeClassName(BaseActivationFactoryProxy* @this, HSTRING* className) { try { if (className is null) { - return E.E_INVALIDARG; + return HRESULT.E_INVALIDARG; } BaseActivationFactory? factory = Unsafe.As(@this->_factory.Target); if (factory is null) { - return E.E_HANDLE; + return HRESULT.E_HANDLE; } string? fullName = factory.GetType().FullName; if (fullName is null) { - return E.E_UNEXPECTED; + return HRESULT.E_UNEXPECTED; } fixed (char* fullNamePtr = fullName) { - return WinString.WindowsCreateString((ushort*)fullNamePtr, (uint)fullName.Length, className); + return WindowsCreateString((PCWSTR)fullNamePtr, (uint)fullName.Length, className); } } catch (Exception e) { - return Marshal.GetHRForException(e); + return (HRESULT)Marshal.GetHRForException(e); } } - public static int GetTrustLevel(BaseActivationFactoryProxy* @this, TrustLevel* trustLevel) + public static HRESULT GetTrustLevel(BaseActivationFactoryProxy* @this, TrustLevel* trustLevel) { if (trustLevel is null) { - return E.E_INVALIDARG; + return HRESULT.E_INVALIDARG; } *trustLevel = TrustLevel.BaseTrust; - return S.S_OK; + return HRESULT.S_OK; } - public static int ActivateInstance(BaseActivationFactoryProxy* @this, IInspectable** instance) + public static HRESULT ActivateInstance(BaseActivationFactoryProxy* @this, IInspectable** instance) { try { if (instance is null) { - return E.E_INVALIDARG; + return HRESULT.E_INVALIDARG; } BaseActivationFactory? factory = Unsafe.As(@this->_factory.Target); if (factory is null) { - return E.E_HANDLE; + return HRESULT.E_HANDLE; } object managedInstance = factory.ActivateInstance(); using ComPtr unkwnPtr = default; unkwnPtr.Attach((IUnknown*)Marshal.GetIUnknownForObject(managedInstance)); - int result = unkwnPtr.CopyTo(instance); - if (result != S.S_OK) + HRESULT result = unkwnPtr.CopyTo(instance); + if (result != HRESULT.S_OK) { return result; } factory.OnInstanceCreated(managedInstance); - return S.S_OK; + return HRESULT.S_OK; } catch (Exception e) { - return Marshal.GetHRForException(e); + return (HRESULT)Marshal.GetHRForException(e); } } } diff --git a/src/Shmuelie.WinRTServer/Internal/BaseClassFactoryProxy.cs b/src/Shmuelie.WinRTServer/Internal/BaseClassFactoryProxy.cs index 8b7a981..31ca47c 100644 --- a/src/Shmuelie.WinRTServer/Internal/BaseClassFactoryProxy.cs +++ b/src/Shmuelie.WinRTServer/Internal/BaseClassFactoryProxy.cs @@ -2,9 +2,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; -using Shmuelie.Interop.Windows; -using static Shmuelie.Interop.Windows.ComBaseAPI; -using static Shmuelie.Interop.Windows.Windows; +using Windows.Win32.Foundation; +using Windows.Win32.System.Com; +using static Windows.Win32.PInvoke; namespace Shmuelie.WinRTServer; @@ -63,7 +63,7 @@ public uint Release() private static class Impl { [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int QueryInterfaceDelegate(BaseClassFactoryProxy* @this, Guid* riid, void** ppvObject); + public delegate HRESULT QueryInterfaceDelegate(BaseClassFactoryProxy* @this, Guid* riid, void** ppvObject); [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate uint AddRefDelegate(BaseClassFactoryProxy* @this); @@ -72,10 +72,10 @@ private static class Impl public delegate uint ReleaseDelegate(BaseClassFactoryProxy* @this); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int CreateInstanceDelegate(BaseClassFactoryProxy* @this, IUnknown* pUnkOuter, Guid* riid, void** ppvObject); + public delegate HRESULT CreateInstanceDelegate(BaseClassFactoryProxy* @this, IUnknown* pUnkOuter, Guid* riid, void** ppvObject); [UnmanagedFunctionPointer(CallingConvention.StdCall)] - public delegate int LockServerDelegate(BaseClassFactoryProxy* @this, int fLock); + public delegate HRESULT LockServerDelegate(BaseClassFactoryProxy* @this, int fLock); /// /// The cached for IUnknown.QueryInterface(REFIID, void**). @@ -99,19 +99,19 @@ private static class Impl /// /// Implements IUnknown.QueryInterface(REFIID, void**). /// - private static int QueryInterface(BaseClassFactoryProxy* @this, Guid* riid, void** ppvObject) + private static HRESULT QueryInterface(BaseClassFactoryProxy* @this, Guid* riid, void** ppvObject) { - if (riid->Equals(__uuidof()) || - riid->Equals(__uuidof())) + if (riid->Equals(IUnknown.IID_Guid) || + riid->Equals(IClassFactory.IID_Guid)) { _ = Interlocked.Increment(ref Unsafe.As(ref @this->_referenceCount)); *ppvObject = @this; - return S.S_OK; + return HRESULT.S_OK; } - return E.E_NOINTERFACE; + return HRESULT.E_NOINTERFACE; } /// @@ -139,30 +139,30 @@ public static uint Release(BaseClassFactoryProxy* @this) return referenceCount; } - public static int CreateInstance(BaseClassFactoryProxy* @this, IUnknown* pUnkOuter, Guid* riid, void** ppvObject) + public static HRESULT CreateInstance(BaseClassFactoryProxy* @this, IUnknown* pUnkOuter, Guid* riid, void** ppvObject) { try { if (pUnkOuter is not null) { - return WinError.CLASS_E_NOAGGREGATION; + return HRESULT.CLASS_E_NOAGGREGATION; } BaseClassFactory? factory = Unsafe.As(@this->_factory.Target); if (factory is null) { - return E.E_HANDLE; + return HRESULT.E_HANDLE; } - if (!riid->Equals(__uuidof()) && !riid->Equals(factory.Iid)) + if (!riid->Equals(IUnknown.IID_Guid) && !riid->Equals(factory.Iid)) { - return E.E_NOINTERFACE; + return HRESULT.E_NOINTERFACE; } var instance = factory.CreateInstance(); - if (riid->Equals(__uuidof())) + if (riid->Equals(IUnknown.IID_Guid)) { *ppvObject = (void*)Marshal.GetIUnknownForObject(instance); } @@ -172,7 +172,7 @@ public static int CreateInstance(BaseClassFactoryProxy* @this, IUnknown* pUnkOut if (t is null) { - return E.E_UNEXPECTED; + return HRESULT.E_UNEXPECTED; } *ppvObject = (void*)Marshal.GetComInterfaceForObject(instance, t); @@ -182,12 +182,12 @@ public static int CreateInstance(BaseClassFactoryProxy* @this, IUnknown* pUnkOut } catch (Exception e) { - return Marshal.GetHRForException(e); + return (HRESULT)Marshal.GetHRForException(e); } - return S.S_OK; + return HRESULT.S_OK; } - public static int LockServer(BaseClassFactoryProxy* @this, int fLock) + public static HRESULT LockServer(BaseClassFactoryProxy* @this, int fLock) { try { @@ -202,9 +202,9 @@ public static int LockServer(BaseClassFactoryProxy* @this, int fLock) } catch (Exception e) { - return Marshal.GetHRForException(e); + return (HRESULT)Marshal.GetHRForException(e); } - return S.S_OK; + return HRESULT.S_OK; } } } diff --git a/src/Shmuelie.WinRTServer/NativeMethods.json b/src/Shmuelie.WinRTServer/NativeMethods.json new file mode 100644 index 0000000..38318d6 --- /dev/null +++ b/src/Shmuelie.WinRTServer/NativeMethods.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://aka.ms/CsWin32.schema.json", + "allowMarshaling": false, + "comInterop": { + "preserveSigMethods": [ "*" ] + }, + "useSafeHandles": false +} diff --git a/src/Shmuelie.WinRTServer/NativeMethods.txt b/src/Shmuelie.WinRTServer/NativeMethods.txt new file mode 100644 index 0000000..1aaebe3 --- /dev/null +++ b/src/Shmuelie.WinRTServer/NativeMethods.txt @@ -0,0 +1,24 @@ +WindowsCreateString +IInspectable +IUnknown +IActivationFactory +E_NOINTERFACE +S_OK +E_INVALIDARG +E_HANDLE +E_UNEXPECTED +IClassFactory +CLASS_E_NOAGGREGATION +CoAddRefServerProcess +CoReleaseServerProcess +IGlobalOptions +CoCreateInstance +CoRegisterClassObject +CoRevokeClassObject +CoResumeClassObjects +CoSuspendClassObjects +RoInitialize +RoRegisterActivationFactories +RoRevokeActivationFactories +S_FALSE +GLOBALOPT_RO_FLAGS \ No newline at end of file diff --git a/src/Shmuelie.WinRTServer/Shmuelie.WinRTServer.csproj b/src/Shmuelie.WinRTServer/Shmuelie.WinRTServer.csproj index 49450e2..6299a57 100644 --- a/src/Shmuelie.WinRTServer/Shmuelie.WinRTServer.csproj +++ b/src/Shmuelie.WinRTServer/Shmuelie.WinRTServer.csproj @@ -16,7 +16,10 @@ - + + all + runtime; build; native; contentfiles; analyzers + diff --git a/src/Shmuelie.WinRTServer/WinRtServer.cs b/src/Shmuelie.WinRTServer/WinRtServer.cs index 33ab885..5bc9c4d 100644 --- a/src/Shmuelie.WinRTServer/WinRtServer.cs +++ b/src/Shmuelie.WinRTServer/WinRtServer.cs @@ -4,11 +4,11 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Timers; +using Windows.Win32.System.WinRT; +using Windows.Win32.System.Com; +using Windows.Win32.Foundation; +using static Windows.Win32.PInvoke; using Shmuelie.Interop.Windows; -using static Shmuelie.Interop.Windows.ComBaseAPI; -using static Shmuelie.Interop.Windows.RoAPI; -using static Shmuelie.Interop.Windows.Windows; -using static Shmuelie.Interop.Windows.WinString; namespace Shmuelie.WinRTServer; @@ -17,13 +17,16 @@ namespace Shmuelie.WinRTServer; /// /// /// +#if !NETSTANDARD +[System.Runtime.Versioning.SupportedOSPlatform("windows8.0")] +#endif public sealed class WinRtServer : IAsyncDisposable { private readonly Dictionary factories = []; - private readonly DllGetActivationFactory activationFactoryCallbackWrapper; + private readonly unsafe Delegate activationFactoryCallbackWrapper; - private unsafe readonly delegate* unmanaged[Stdcall] activationFactoryCallbackPointer; + private unsafe readonly delegate* unmanaged[Stdcall] activationFactoryCallbackPointer; /// /// Collection of created instances. @@ -40,7 +43,7 @@ public sealed class WinRtServer : IAsyncDisposable /// private TaskCompletionSource? firstInstanceCreated; - private RO_REGISTRATION_COOKIE registrationCookie = RO_REGISTRATION_COOKIE.NULL; + private RO_REGISTRATION_COOKIE registrationCookie = (RO_REGISTRATION_COOKIE)0; /// /// Initializes a new instance of the class. @@ -48,17 +51,18 @@ public sealed class WinRtServer : IAsyncDisposable public unsafe WinRtServer() { activationFactoryCallbackWrapper = ActivationFactoryCallback; - activationFactoryCallbackPointer = (delegate* unmanaged[Stdcall])Marshal.GetFunctionPointerForDelegate(activationFactoryCallbackWrapper); + activationFactoryCallbackPointer = (delegate* unmanaged[Stdcall])Marshal.GetFunctionPointerForDelegate(activationFactoryCallbackWrapper); - int result = RoInitialize(RO_INIT_TYPE.RO_INIT_MULTITHREADED); - if (result != S.S_OK && result != S.S_FALSE) + HRESULT result = RoInitialize(RO_INIT_TYPE.RO_INIT_MULTITHREADED); + if (result != HRESULT.S_OK && result != HRESULT.S_FALSE) { Marshal.ThrowExceptionForHR(result); } using ComPtr options = default; - Guid clsid = IGlobalOptions.CLSID; - if (CoCreateInstance(&clsid, null, (uint)CLSCTX.CLSCTX_INPROC_SERVER, __uuidof(), (void**)options.GetAddressOf()) == S.S_OK) + Guid clsid = CLSID_GlobalOptions; + Guid iid = IGlobalOptions.IID_Guid; + if (CoCreateInstance(&clsid, null, CLSCTX.CLSCTX_INPROC_SERVER, &iid, (void**)options.GetAddressOf()) == HRESULT.S_OK) { options.Get()->Set(GLOBALOPT_PROPERTIES.COMGLB_RO_SETTINGS, (nuint)GLOBALOPT_RO_FLAGS.COMGLB_FAST_RUNDOWN); } @@ -172,21 +176,21 @@ public bool UnregisterActivationFactory(BaseActivationFactory factory) return factories.Remove(factory.ActivatableClassId); } - private unsafe int ActivationFactoryCallback(HSTRING activatableClassId, IActivationFactory** factory) + private unsafe HRESULT ActivationFactoryCallback(HSTRING activatableClassId, IActivationFactory** factory) { - if (activatableClassId == HSTRING.NULL || factory is null) + if (activatableClassId == HSTRING.Null || factory is null) { - return E.E_INVALIDARG; + return HRESULT.E_INVALIDARG; } if (!factories.TryGetValue(activatableClassId.ToString(), out BaseActivationFactory? managedFactory)) { factory = null; - return E.E_NOINTERFACE; + return HRESULT.E_NOINTERFACE; } *factory = (IActivationFactory*)BaseActivationFactoryProxy.Create(managedFactory); - return S.S_OK; + return HRESULT.S_OK; } /// @@ -201,7 +205,7 @@ public bool IsDisposed /// /// Gets a value indicating whether the server is running. /// - public bool IsRunning => registrationCookie != RO_REGISTRATION_COOKIE.NULL; + public bool IsRunning => registrationCookie != 0; /// /// Starts the server. @@ -219,7 +223,7 @@ public unsafe void Start() string[] managedActivatableClassIds = [.. factories.Keys]; HSTRING* activatableClassIds = null; - delegate* unmanaged[Stdcall]* activationFactoryCallbacks = null; + delegate* unmanaged[Stdcall]* activationFactoryCallbacks = null; try { activatableClassIds = (HSTRING*)Marshal.AllocHGlobal(sizeof(HSTRING) * managedActivatableClassIds.Length); @@ -228,11 +232,11 @@ public unsafe void Start() string managedActivatableClassId = managedActivatableClassIds[activatableClassIdIndex]; fixed (char* managedActivatableClassIdPtr = managedActivatableClassId) { - Marshal.ThrowExceptionForHR(WindowsCreateString((ushort*)managedActivatableClassIdPtr, (uint)managedActivatableClassId.Length, &activatableClassIds[activatableClassIdIndex])); + Marshal.ThrowExceptionForHR(WindowsCreateString((PCWSTR)managedActivatableClassIdPtr, (uint)managedActivatableClassId.Length, &activatableClassIds[activatableClassIdIndex])); } } - activationFactoryCallbacks = (delegate* unmanaged[Stdcall]*)Marshal.AllocHGlobal(sizeof(delegate* unmanaged[Stdcall]*) * managedActivatableClassIds.Length); + activationFactoryCallbacks = (delegate* unmanaged[Stdcall]*)Marshal.AllocHGlobal(sizeof(delegate* unmanaged[Stdcall]*) * managedActivatableClassIds.Length); for (int activationFactoryCallbackIndex = 0; activationFactoryCallbackIndex < managedActivatableClassIds.Length; activationFactoryCallbackIndex++) { activationFactoryCallbacks[activationFactoryCallbackIndex] = activationFactoryCallbackPointer; @@ -278,7 +282,7 @@ public void Stop() } RoRevokeActivationFactories(registrationCookie); - registrationCookie = RO_REGISTRATION_COOKIE.NULL; + registrationCookie = (RO_REGISTRATION_COOKIE)0; firstInstanceCreated = null; lifetimeCheckTimer.Stop(); @@ -328,7 +332,7 @@ void Ended(object? sender, EventArgs e) lifetimeCheckTimer.Dispose(); RoRevokeActivationFactories(registrationCookie); - registrationCookie = RO_REGISTRATION_COOKIE.NULL; + registrationCookie = (RO_REGISTRATION_COOKIE)0; } finally { diff --git a/src/Shmuelie.WinRTServer/WinRtServerExtensions.cs b/src/Shmuelie.WinRTServer/WinRtServerExtensions.cs index 6437966..75f29e0 100644 --- a/src/Shmuelie.WinRTServer/WinRtServerExtensions.cs +++ b/src/Shmuelie.WinRTServer/WinRtServerExtensions.cs @@ -5,6 +5,9 @@ namespace Shmuelie.WinRTServer; /// /// Extensions for . /// +#if !NETSTANDARD +[System.Runtime.Versioning.SupportedOSPlatform("windows8.0")] +#endif public static class WinRtServerExtensions { /// diff --git a/src/Shmuelie.WinRTServer/Windows/Win32/PInvoke.cs b/src/Shmuelie.WinRTServer/Windows/Win32/PInvoke.cs new file mode 100644 index 0000000..abf3ef1 --- /dev/null +++ b/src/Shmuelie.WinRTServer/Windows/Win32/PInvoke.cs @@ -0,0 +1,8 @@ +using System; + +namespace Windows.Win32; + +internal partial class PInvoke +{ + public static readonly Guid CLSID_GlobalOptions = new(0x0000034b, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); +} diff --git a/src/Shmuelie.WinRTServer/Windows/shared/uuids/__uuidof.cs b/src/Shmuelie.WinRTServer/Windows/shared/uuids/__uuidof.cs index a25637f..de1e2fc 100644 --- a/src/Shmuelie.WinRTServer/Windows/shared/uuids/__uuidof.cs +++ b/src/Shmuelie.WinRTServer/Windows/shared/uuids/__uuidof.cs @@ -1,4 +1,5 @@ -using System; +#if NETSTANDARD +using System; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -120,4 +121,5 @@ private static unsafe class UUID } } -#pragma warning restore IDE1006 // Naming Styles \ No newline at end of file +#pragma warning restore IDE1006 // Naming Styles +#endif \ No newline at end of file diff --git a/src/Shmuelie.WinRTServer/Windows/shared/winerror/E.cs b/src/Shmuelie.WinRTServer/Windows/shared/winerror/E.cs deleted file mode 100644 index 28e5f3b..0000000 --- a/src/Shmuelie.WinRTServer/Windows/shared/winerror/E.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -/// -/// See . -/// -internal static partial class E -{ - /// - /// No such interface supported - /// - public const int E_NOINTERFACE = unchecked((int)(0x80004002)); - - /// - /// Handle that is not valid - /// - public const int E_HANDLE = unchecked((int)(0x80070006)); - - /// - /// Unexpected failure - /// - public const int E_UNEXPECTED = unchecked((int)(0x8000FFFF)); - - /// - /// One or more arguments are not valid - /// - public const int E_INVALIDARG = unchecked((int)0x80070057); -} \ No newline at end of file diff --git a/src/Shmuelie.WinRTServer/Windows/shared/winerror/S.cs b/src/Shmuelie.WinRTServer/Windows/shared/winerror/S.cs deleted file mode 100644 index ddafbcf..0000000 --- a/src/Shmuelie.WinRTServer/Windows/shared/winerror/S.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -/// -/// See . -/// -internal static class S -{ - /// - /// Operation successful - /// - public const int S_OK = 0; - - /// - /// A negative condition that is not a failure. - /// - public const int S_FALSE = 1; -} diff --git a/src/Shmuelie.WinRTServer/Windows/shared/winerror/WinError.cs b/src/Shmuelie.WinRTServer/Windows/shared/winerror/WinError.cs deleted file mode 100644 index 004fd9d..0000000 --- a/src/Shmuelie.WinRTServer/Windows/shared/winerror/WinError.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -internal static class WinError -{ - /// - /// Class aggregation is not supported. - /// - public const int CLASS_E_NOAGGREGATION = unchecked((int)(0x80040110)); -} diff --git a/src/Shmuelie.WinRTServer/Windows/shared/wtypesbase/CLSCTX.cs b/src/Shmuelie.WinRTServer/Windows/shared/wtypesbase/CLSCTX.cs deleted file mode 100644 index fd976df..0000000 --- a/src/Shmuelie.WinRTServer/Windows/shared/wtypesbase/CLSCTX.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -/// -/// Values that are used in activation calls to indicate the execution contexts in which an object is to be run. -/// -/// CLSCTX enumeration (wtypesbase.h) -internal enum CLSCTX -{ - /// - /// The code that creates and manages objects of this class is a DLL that runs in the same process as the caller of the function specifying the class context. - /// - CLSCTX_INPROC_SERVER = 0x1, - - /// - /// The EXE code that creates and manages objects of this class runs on same machine but is loaded in a separate process space. - /// - CLSCTX_LOCAL_SERVER = 0x4, -} diff --git a/src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IClassFactory.cs b/src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IClassFactory.cs deleted file mode 100644 index f140286..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IClassFactory.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// Enables a class of objects to be created. -/// -/// IClassFactory interface (unknwn.h) -[Guid("00000001-0000-0000-C000-000000000046")] -internal unsafe partial struct IClassFactory -{ -#pragma warning disable CS0649 // This field maps to the native object directly - public void** lpVtbl; -#pragma warning restore CS0649 - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int QueryInterface(Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IClassFactory*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IClassFactory*)Unsafe.AsPointer(ref this)); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IClassFactory*)Unsafe.AsPointer(ref this)); - } - - /// - /// Creates an uninitialized object. - /// - /// If the object is being created as part of an aggregate, specify a pointer to the controlling interface of the aggregate. Otherwise, this parameter must be . - /// A reference to the identifier of the interface to be used to communicate with the newly created object. If is , this parameter is generally the IID of the initializing interface; if is not , must be IID of . - /// The address of pointer variable that receives the interface pointer requested in . Upon successful return, * contains the requested interface pointer. If the object does not support the interface specified in , the implementation must set * to . - /// - /// This method can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. - /// - /// - /// Return Code - /// Description - /// - /// - /// S_OK - /// The specified object was created. - /// - /// - /// CLASS_E_NOAGGREGATION - /// The parameter was not and the object does not support aggregation. - /// - /// - /// E_NOINTERFACE - /// The object that points to does not support the interface identified by . - /// - /// - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int CreateInstance(IUnknown* pUnkOuter, Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IClassFactory*)Unsafe.AsPointer(ref this), pUnkOuter, riid, ppvObject); - } - - /// - /// Locks an object application open in memory. This enables instances to be created more quickly. - /// - /// If TRUE, increments the lock count; if FALSE, decrements the lock count. - /// This method can return the standard return values E_OUTOFMEMORY, E_UNEXPECTED, E_FAIL, and S_OK. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int LockServer(int fLock) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IClassFactory*)Unsafe.AsPointer(ref this), fLock); - } -} diff --git a/src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IUnknown.cs b/src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IUnknown.cs deleted file mode 100644 index 04eaca1..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/Unknwnbase/IUnknown.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// A struct mapping the native COM IUnknown interface. -/// -/// IUnknown interface (unknwn.h) -[Guid("00000000-0000-0000-C000-000000000046")] -internal unsafe struct IUnknown -{ -#pragma warning disable CS0649 // This field maps to the native object directly - /// - /// The vtable pointer for the current instance. - /// - /// - /// This field is never initialized in C#. - /// - private readonly void** lpVtbl; -#pragma warning restore CS0649 - - /// - /// Queries a COM object for a pointer to one of its interface; identifying the interface by a reference to its interface identifier (IID). - /// If the COM object implements the interface, then it returns a pointer to that interface after calling on it. - /// - /// IUnknown.QueryInterface(REFIID, void**) - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int QueryInterface(Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])lpVtbl[0])((IUnknown*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - /// - /// Increments the reference count for an interface pointer to a COM object. You should call this method whenever you make a copy of an interface pointer. - /// - /// IUnknown.AddRef() - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])lpVtbl[1])((IUnknown*)Unsafe.AsPointer(ref this)); - } - - /// - /// Decrements the reference count for an interface on a COM object. - /// - /// IUnknown.Release() - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])lpVtbl[2])((IUnknown*)Unsafe.AsPointer(ref this)); - } -} diff --git a/src/Shmuelie.WinRTServer/Windows/um/combaseapi/ComBaseAPI.cs b/src/Shmuelie.WinRTServer/Windows/um/combaseapi/ComBaseAPI.cs deleted file mode 100644 index 2790b66..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/combaseapi/ComBaseAPI.cs +++ /dev/null @@ -1,203 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// APIs from the combaseapi header. -/// -internal static unsafe -#if NET8_0_OR_GREATER - partial -#endif - class ComBaseAPI -{ - /// - /// Creates and default-initializes a single object of the class associated with a specified CLSID. - /// - /// The CLSID associated with the data and code that will be used to create the object. - /// If , indicates that the object is not being created as part of an aggregate. If non-, pointer to the aggregate object's interface (the controlling ). - /// Context in which the code that manages the newly created object will run. The values are taken from the enumeration . - /// A reference to the identifier of the interface to be used to communicate with the object. - /// Address of pointer variable that receives the interface pointer requested in . Upon successful return, * contains the requested interface pointer. Upon failure, * contains . - /// - /// This function can return the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// An instance of the specified object class was successfully created. - /// - /// - /// REGDB_E_CLASSNOTREG - /// A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the enumeration is not registered or the values for the server types in the registry are corrupt. - /// - /// - /// CLASS_E_NOAGGREGATION - /// This class cannot be created as part of an aggregate. - /// - /// - /// E_NOINTERFACE - /// The specified class does not implement the requested interface, or the controlling does not expose the requested interface. - /// - /// - /// E_POINTER - /// The parameter is . - /// - /// - /// - /// CoCreateInstance function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int CoCreateInstance(Guid* rclsid, IUnknown* pUnkOuter, uint dwClsContext, Guid* riid, void** ppv); - - /// - /// Registers an EXE class object with OLE so other applications can connect to it. - /// - /// The CLSID to be registered. - /// A pointer to the interface on the class object whose availability is being published. - /// The context in which the executable code is to be run. For information on these context values, see the enumeration. - /// Indicates how connections are made to the class object. For information on these flags, see the enumeration. - /// A pointer to a value that identifies the class object registered; later used by the function to revoke the registration. - /// - /// This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The class object was registered successfully. - /// - /// - /// - /// CoRegisterClassObject function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int CoRegisterClassObject(Guid* rclsid, IUnknown* pUnk, uint dwClsContext, uint flags, uint* lpdwRegister); - - /// - /// Called by a server that can register multiple class objects to inform the SCM about all registered classes, and permits activation requests for those class objects. - /// - /// This function returns S_OK to indicate that the activation of class objects was successfully resumed. - /// CoResumeClassObjects function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int CoResumeClassObjects(); - - /// - /// Prevents any new activation requests from the SCM on all class objects registered within the process. - /// - /// This function returns S_OK to indicate that the activation of class objects was successfully suspended. - /// CoSuspendClassObjects function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int CoSuspendClassObjects(); - - /// - /// Increments a global per-process reference count. - /// - /// The current reference count. - /// CoAddRefServerProcess function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - uint CoAddRefServerProcess(); - - /// - /// Decrements the global per-process reference count. - /// - /// If the server application should initiate its cleanup, the function returns 0; otherwise, the function returns a nonzero value. - /// CoReleaseServerProcess function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - uint CoReleaseServerProcess(); - - /// - /// Informs OLE that a class object, previously registered with the function, is no longer available for use. - /// - /// A token previously returned from the function. - /// - /// This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The class object was revoked successfully. - /// - /// - /// - /// CoRevokeClassObject function (combaseapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("ole32")] -#else - [DllImport("ole32", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int CoRevokeClassObject(uint dwRegister); -} \ No newline at end of file diff --git a/src/Shmuelie.WinRTServer/Windows/um/combaseapi/REGCLS.cs b/src/Shmuelie.WinRTServer/Windows/um/combaseapi/REGCLS.cs deleted file mode 100644 index f044146..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/combaseapi/REGCLS.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; - -namespace Shmuelie.Interop.Windows; - -/// -/// Controls the type of connections to a class object. -/// -/// REGCLS enumeration (combaseapi.h) -[Flags] -internal enum REGCLS -{ - /// - /// Multiple applications can connect to the class object through calls to - /// CoGetClassObject. If both the - /// and are set in a call to , the class object is also automatically registered as an - /// in-process server, whether CLSCTX_INPROC_SERVER is explicitly - /// set. - /// - REGCLS_MULTIPLEUSE = 1, - /// - /// Suspends registration and activation requests for the specified CLSID - /// until there is a call to . - /// This is used typically to register the CLSIDs for servers that can - /// register multiple class objects to reduce the overall registration time, - /// and thus the server application startup time, by making a single call to - /// the SCM, no matter how many CLSIDs are registered for the server. - /// - REGCLS_SUSPENDED = 4, -} diff --git a/src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_PROPERTIES.cs b/src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_PROPERTIES.cs deleted file mode 100644 index bf06d4d..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_PROPERTIES.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -/// -/// Identifies process-global options that you can set or query by using the interface. -/// -/// -internal enum GLOBALOPT_PROPERTIES -{ - /// - /// Used for miscellaneous settings. - /// - COMGLB_RO_SETTINGS = 4, -} diff --git a/src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_RO_FLAGS.cs b/src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_RO_FLAGS.cs deleted file mode 100644 index 3e44f55..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/objidlbase/GLOBALOPT_RO_FLAGS.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Shmuelie.Interop.Windows; - -[Flags] -internal enum GLOBALOPT_RO_FLAGS -{ - /// - /// Indicates that stubs in the current process are subjected to fast stub rundown behavior, which means that stubs are run down on termination of the client process, instead of waiting for normal cleanup timeouts to expire. - /// - COMGLB_FAST_RUNDOWN = 0x8, -} diff --git a/src/Shmuelie.WinRTServer/Windows/um/objidlbase/IGlobalOptions.cs b/src/Shmuelie.WinRTServer/Windows/um/objidlbase/IGlobalOptions.cs deleted file mode 100644 index e288220..0000000 --- a/src/Shmuelie.WinRTServer/Windows/um/objidlbase/IGlobalOptions.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// Sets and queries global properties of the Component Object Model (COM) runtime. -/// -/// IGlobalOptions interface (objidlbase.h) -[Guid("0000015B-0000-0000-C000-000000000046")] -internal unsafe partial struct IGlobalOptions -{ - /// - /// The CLSID for . - /// - public static readonly Guid CLSID = new(0x0000034b, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); - -#pragma warning disable CS0649 - public void** lpVtbl; -#pragma warning restore CS0649 - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int QueryInterface(Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IGlobalOptions*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IGlobalOptions*)Unsafe.AsPointer(ref this)); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IGlobalOptions*)Unsafe.AsPointer(ref this)); - } - - /// - /// Sets the specified global property of the COM runtime. - /// - /// The global property of the COM runtime. For a list of properties that can be set with this method, see . - /// The value of the property.Important For the COMGLB_APPID property, this parameter must specify a pointer to the APPID GUID. - /// The return value is S_OK if the property was set successfully. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Set(GLOBALOPT_PROPERTIES dwProperty, nuint dwValue) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IGlobalOptions*)Unsafe.AsPointer(ref this), dwProperty, dwValue); - } - - /// - /// Queries the specified global property of the COM runtime. - /// - /// The global property of the COM runtime. For a list of properties that can be set with this method, see . - /// The value of the property.Important For the COMGLB_APPID property, this parameter receives a pointer to the AppID GUID. - /// The return value is S_OK if the property is queried successfully. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Query(GLOBALOPT_PROPERTIES dwProperty, nuint* pdwValue) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IGlobalOptions*)Unsafe.AsPointer(ref this), dwProperty, pdwValue); - } -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/HSTRING.cs b/src/Shmuelie.WinRTServer/Windows/winrt/HSTRING.cs deleted file mode 100644 index f4e9265..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/HSTRING.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -#if NETSTANDARD2_0 -using static Shmuelie.WinRTServer.UIntPtrExtensions; -#endif - -namespace Shmuelie.Interop.Windows; - -/// -/// A sequential collection of UTF-16 Unicode characters representing a text string. The type encapsulates HSTRING behind an interface similar to that of . A HSTRING is a handle to a Windows Runtime string. -/// -internal readonly unsafe partial struct HSTRING : IComparable, IComparable, IEquatable, IFormattable -{ - private readonly void* Value; - - /// - /// Initializes a new instance of the struct. - /// - /// The pointer to the native HSTRING. - private HSTRING(void* value) - { - Value = value; - } - - public static HSTRING INVALID_VALUE => new HSTRING((void*)(-1)); - - public static HSTRING NULL => new HSTRING(null); - - public static bool operator ==(HSTRING left, HSTRING right) => left.Equals(right); - - public static bool operator !=(HSTRING left, HSTRING right) => !left.Equals(right); - - /// - public int CompareTo(object? obj) - { - if (obj is HSTRING other) - { - return CompareTo(other); - } - - return (obj is null) ? 1 : throw new ArgumentException("obj is not an instance of HSTRING."); - } - - /// - public int CompareTo(HSTRING other) - { - int result; - _ = WinString.WindowsCompareStringOrdinal(this, other, &result); - return result; - } - - /// - public override bool Equals(object? obj) => (obj is HSTRING other) && Equals(other); - - /// - public bool Equals(HSTRING other) => CompareTo(other) == 0; - - /// - public override int GetHashCode() - { - uint characterCount; - ushort* characters = WinString.WindowsGetStringRawBuffer(this, &characterCount); - - if (characterCount == 0) - { - return string.Empty.GetHashCode(); - } - - HashCode hashCode = new(); - for (uint characterIndex = 0; characterIndex < characterCount; characterIndex++) - { - hashCode.Add(characters[characterIndex]); - } - return hashCode.ToHashCode(); - } - - /// - public override string ToString() - { - if (Value is null) - { - return string.Empty; - } - - uint characterCount; - ushort* characters = WinString.WindowsGetStringRawBuffer(this, &characterCount); - - if (characters is null || characterCount == 0) - { - return string.Empty; - } - - return new string((char*)characters, 0, (int)characterCount); - } - - /// - /// - /// If is x or X, the instance is formatted an . - /// - public string ToString(string? format, IFormatProvider? formatProvider) - { - if (format is null) - { - return ToString(); - } - - if (format.Equals("x", StringComparison.OrdinalIgnoreCase)) - { - return ((nuint)(Value)).ToString(format, formatProvider); - } - - throw new FormatException("Unsupported format"); - } -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/activation/IActivationFactory.cs b/src/Shmuelie.WinRTServer/Windows/winrt/activation/IActivationFactory.cs deleted file mode 100644 index edd51b7..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/activation/IActivationFactory.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// Enables classes to be activated by the Windows Runtime. -/// -/// IActivationFactory interface (activation.h) -[Guid("00000035-0000-0000-C000-000000000046")] -internal unsafe partial struct IActivationFactory -{ -#pragma warning disable CS0649 // This field maps to the native object directly - public void** lpVtbl; -#pragma warning restore CS0649 - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int QueryInterface(Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IActivationFactory*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IActivationFactory*)Unsafe.AsPointer(ref this)); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IActivationFactory*)Unsafe.AsPointer(ref this)); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetIids(uint* iidCount, Guid** iids) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IActivationFactory*)Unsafe.AsPointer(ref this), iidCount, iids); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetRuntimeClassName(HSTRING* className) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IActivationFactory*)Unsafe.AsPointer(ref this), className); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetTrustLevel(TrustLevel* trustLevel) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((IActivationFactory*)Unsafe.AsPointer(ref this), trustLevel); - } - - /// - /// Creates a new instance of the Windows Runtime class that is associated with the current activation factory. - /// - /// A pointer to a new instance of the class that is associated with the current activation factory. - /// - /// This function can return the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The new class instance was created successfully. - /// - /// - /// E_INVALIDARG - /// is . - /// - /// - /// E_NOINTERFACE - /// The interface is not implemented by the class that is associated with the current activation factory. - /// - /// - /// E_OUTOFMEMORY - /// Failed to create an instance of the class. - /// - /// - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int ActivateInstance(IInspectable** instance) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[6]))((IActivationFactory*)Unsafe.AsPointer(ref this), instance); - } -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/inspectable/IInspectable.cs b/src/Shmuelie.WinRTServer/Windows/winrt/inspectable/IInspectable.cs deleted file mode 100644 index bcec89f..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/inspectable/IInspectable.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// Provides functionality required for all Windows Runtime classes. -/// -/// IInspectable interface (inspectable.h) -[Guid("AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90")] -internal unsafe partial struct IInspectable -{ -#pragma warning disable CS0649 // This field maps to the native object directly - public void** lpVtbl; -#pragma warning restore CS0649 - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int QueryInterface(Guid* riid, void** ppvObject) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IInspectable*)Unsafe.AsPointer(ref this), riid, ppvObject); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint AddRef() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IInspectable*)Unsafe.AsPointer(ref this)); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint Release() - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IInspectable*)Unsafe.AsPointer(ref this)); - } - - /// - /// Gets the interfaces that are implemented by the current Windows Runtime class. - /// - /// The number of interfaces that are implemented by the current Windows Runtime object, excluding the and implementations. - /// A pointer to an array that contains an IID for each interface implemented by the current Windows Runtime object. The and interfaces are excluded. - /// - /// This function can return the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The was created successfully. - /// - /// - /// E_OUTOFMEMORY - /// Failed to allocate . - /// - /// - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetIids(uint* iidCount, Guid** iids) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((IInspectable*)Unsafe.AsPointer(ref this), iidCount, iids); - } - - /// - /// Gets the fully qualified name of the current Windows Runtime object. - /// - /// The fully qualified name of the current Windows Runtime object. - /// - /// This function can return the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The string was created successfully. - /// - /// - /// E_OUTOFMEMORY - /// Failed to allocate string. - /// - /// - /// E_ILLEGAL_METHOD_CALL - /// refers to a class factory or a static interface. - /// - /// - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetRuntimeClassName(void** className) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((IInspectable*)Unsafe.AsPointer(ref this), className); - } - - /// - /// Gets the trust level of the current Windows Runtime object. - /// - /// The trust level of the current Windows Runtime object. The default is . - /// This method always returns S_OK. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetTrustLevel(TrustLevel* trustLevel) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((IInspectable*)Unsafe.AsPointer(ref this), trustLevel); - } -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/inspectable/TrustLevel.cs b/src/Shmuelie.WinRTServer/Windows/winrt/inspectable/TrustLevel.cs deleted file mode 100644 index eedf80e..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/inspectable/TrustLevel.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -/// -/// Represents the trust level of an activatable class. -/// -/// TrustLevel enumeration (inspectable.h) -internal enum TrustLevel -{ - /// - /// The component has access to resources that are not protected. - /// - BaseTrust = 0, -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/DllGetActivationFactory.cs b/src/Shmuelie.WinRTServer/Windows/winrt/roapi/DllGetActivationFactory.cs deleted file mode 100644 index ab8b934..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/DllGetActivationFactory.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// Retrieves the activation factory from a DLL that contains activatable Windows Runtime classes. -/// -/// The class identifier that is associated with an activatable runtime class. -/// A pointer to the activation factory that corresponds with the class specified by . -/// -/// This entry point can return one of these values. -/// -/// -/// Return code -/// Description -/// -/// -/// S_OK -/// The activation factory was found successfully. -/// -/// -/// E_NOINTERFACE -/// The activation factory corresponding to the class specified by was not found in the DLL. -/// -/// -/// E_INVALIDARG -/// or is . -/// -/// -/// E_OUTOFMEMORY -/// The activation factory store for the class specified by could not be populated. -/// -/// -/// REGDB_E_READREGDB -/// An error occurred while reading the registration database. -/// -/// -/// REGDB_E_CLASSNOTREG -/// The class specified by is not supported. -/// -/// -/// -/// DllGetActivationFactory entry point -[UnmanagedFunctionPointer(CallingConvention.StdCall)] -internal unsafe delegate int DllGetActivationFactory(HSTRING activatableClassId, IActivationFactory** factory); diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_INIT_TYPE.cs b/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_INIT_TYPE.cs deleted file mode 100644 index e1fa02c..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_INIT_TYPE.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Shmuelie.Interop.Windows; - -/// -/// Determines the concurrency model used for incoming calls to the objects created by this thread. -/// -/// RO_INIT_TYPE enumeration (roapi.h) -internal enum RO_INIT_TYPE -{ - /// - /// Initializes the thread for multi-threaded concurrency. The current thread is initialized in the MTA. - /// - RO_INIT_MULTITHREADED = 1 -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_REGISTRATION_COOKIE.cs b/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_REGISTRATION_COOKIE.cs deleted file mode 100644 index c1eea6b..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RO_REGISTRATION_COOKIE.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -#if NETSTANDARD2_0 -using static Shmuelie.WinRTServer.UIntPtrExtensions; -#endif - -namespace Shmuelie.Interop.Windows; - -/// -/// Represents activation factories that are registered by calling the RoRegisterActivationFactories function. -/// -/// RO_REGISTRATION_COOKIE -/// -/// Initializes a new instance of the struct. -/// -/// -internal readonly unsafe partial struct RO_REGISTRATION_COOKIE(void* value) : IComparable, IComparable, IEquatable, IFormattable -{ - private readonly void* Value = value; - - /// - /// Gets a null . - /// - public static RO_REGISTRATION_COOKIE NULL => new RO_REGISTRATION_COOKIE(null); - - public static bool operator ==(RO_REGISTRATION_COOKIE left, RO_REGISTRATION_COOKIE right) => left.Value == right.Value; - - public static bool operator !=(RO_REGISTRATION_COOKIE left, RO_REGISTRATION_COOKIE right) => left.Value != right.Value; - - public static bool operator <(RO_REGISTRATION_COOKIE left, RO_REGISTRATION_COOKIE right) => left.Value < right.Value; - - public static bool operator <=(RO_REGISTRATION_COOKIE left, RO_REGISTRATION_COOKIE right) => left.Value <= right.Value; - - public static bool operator >(RO_REGISTRATION_COOKIE left, RO_REGISTRATION_COOKIE right) => left.Value > right.Value; - - public static bool operator >=(RO_REGISTRATION_COOKIE left, RO_REGISTRATION_COOKIE right) => left.Value >= right.Value; - - public static explicit operator RO_REGISTRATION_COOKIE(void* value) => new RO_REGISTRATION_COOKIE(value); - - public static implicit operator void*(RO_REGISTRATION_COOKIE value) => value.Value; - - public static explicit operator RO_REGISTRATION_COOKIE(byte value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator byte(RO_REGISTRATION_COOKIE value) => (byte)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(short value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator short(RO_REGISTRATION_COOKIE value) => (short)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(int value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator int(RO_REGISTRATION_COOKIE value) => (int)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(long value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator long(RO_REGISTRATION_COOKIE value) => (long)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(nint value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static implicit operator nint(RO_REGISTRATION_COOKIE value) => (nint)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(sbyte value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator sbyte(RO_REGISTRATION_COOKIE value) => (sbyte)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(ushort value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator ushort(RO_REGISTRATION_COOKIE value) => (ushort)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(uint value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator uint(RO_REGISTRATION_COOKIE value) => (uint)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(ulong value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static explicit operator ulong(RO_REGISTRATION_COOKIE value) => (ulong)(value.Value); - - public static explicit operator RO_REGISTRATION_COOKIE(nuint value) => new RO_REGISTRATION_COOKIE(unchecked((void*)(value))); - - public static implicit operator nuint(RO_REGISTRATION_COOKIE value) => (nuint)(value.Value); - - /// - public int CompareTo(object? obj) - { - if (obj is RO_REGISTRATION_COOKIE other) - { - return CompareTo(other); - } - - return (obj is null) ? 1 : throw new ArgumentException("obj is not an instance of RO_REGISTRATION_COOKIE."); - } - - /// - public int CompareTo(RO_REGISTRATION_COOKIE other) => ((nuint)(Value)).CompareTo((nuint)(other.Value)); - - /// - public override bool Equals(object? obj) => (obj is RO_REGISTRATION_COOKIE other) && Equals(other); - - /// - public bool Equals(RO_REGISTRATION_COOKIE other) => ((nuint)(Value)).Equals((nuint)(other.Value)); - - /// - public override int GetHashCode() => ((nuint)(Value)).GetHashCode(); - - /// - public override string ToString() => ((nuint)(Value)).ToString((sizeof(nint) == 4) ? "X8" : "X16"); - - /// - public string ToString(string? format, IFormatProvider? formatProvider) => ((nuint)(Value)).ToString(format, formatProvider); -} \ No newline at end of file diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RoAPI.cs b/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RoAPI.cs deleted file mode 100644 index 73002f6..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/roapi/RoAPI.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// APIs from the roapi header. -/// -internal static unsafe -#if NET8_0_OR_GREATER - partial -#endif - class RoAPI -{ - /// - /// Initializes the Windows Runtime on the current thread with the specified concurrency model. - /// - /// The concurrency model for the thread. The default is . - /// - /// This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The Windows Runtime was initialized successfully on this thread. - /// - /// - /// S_FALSE - /// The Windows Runtime is already initialized on this thread. - /// - /// - /// RPC_E_CHANGED_MODE - /// A previous call to specified the concurrency model for this thread as multithread apartment (MTA). This could also indicate that a change from neutral-threaded apartment to single-threaded apartment has occurred. - /// - /// - /// - /// RoInitialize function (roapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int RoInitialize(RO_INIT_TYPE initType); - - /// - /// Registers an array out-of-process activation factories for a Windows Runtime exe server. - /// - /// An array of class identifiers that are associated with activatable runtime classes. - /// An array of callback functions that you can use to retrieve the activation factories that correspond with . - /// The number of items in the and arrays. - /// A cookie that identifies the registered factories. - /// - /// This function can return one of these values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The activation factory was registered successfully. - /// - /// - /// E_POINTER - /// is - /// - /// - /// CO_E_NOT_SUPPORTED - /// The thread is in a neutral apartment. - /// - /// - /// CO_E_NOTINITIALIZED - /// The thread has not been initialized in the Windows Runtime by calling the function. - /// - /// - /// CO_E_ALREADYINITIALIZED - /// The factory has been initialized already. - /// - /// - /// REGDB_E_CLASSNOTREG - /// The class is not registered as OutOfProc. - /// - /// - /// - /// RoRegisterActivationFactories function (roapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int RoRegisterActivationFactories(HSTRING* activatableClassIds, delegate* unmanaged[Stdcall]* activationFactoryCallbacks, uint count, RO_REGISTRATION_COOKIE* cookie); - - /// - /// Removes an array of registered activation factories from the Windows Runtime. - /// - /// A cookie that identifies the registered factories to remove. - /// RoRevokeActivationFactories function (roapi.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - void RoRevokeActivationFactories(RO_REGISTRATION_COOKIE cookie); -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/winstring/WinString.cs b/src/Shmuelie.WinRTServer/Windows/winrt/winstring/WinString.cs deleted file mode 100644 index 6a4ce87..0000000 --- a/src/Shmuelie.WinRTServer/Windows/winrt/winstring/WinString.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Shmuelie.Interop.Windows; - -/// -/// APIs from the winstring header. -/// -internal static unsafe -#if NET8_0_OR_GREATER - partial -#endif - class WinString -{ - /// - /// Creates a new based on the specified source string. - /// - /// A null-terminated string to use as the source for the new . To create a new, empty, or string, pass for and 0 for . - /// The length of , in Unicode characters. Must be 0 if is . - /// A pointer to the newly created , or if an error occurs. Any existing content in is overwritten. The is a standard handle type. - /// - /// This function can return one of these values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The was created successfully. - /// - /// - /// E_INVALIDARG - /// is . - /// - /// - /// E_OUTOFMEMORY - /// Failed to allocate the new . - /// - /// - /// E_POINTER - /// is and is non-zero. - /// - /// - /// - /// WindowsCreateString function (winstring.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int WindowsCreateString(ushort* sourceString, uint length, HSTRING* @string); - - /// - /// Decrements the reference count of a string buffer. - /// - /// The string to be deleted. If is a fast-pass string created by WindowsCreateStringReference, or if is or empty, no action is taken and S_OK is returned. - /// This function always returns S_OK. - /// WindowsDeleteString function (winstring.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int WindowsDeleteString(HSTRING @string); - - /// - /// Retrieves the backing buffer for the specified string. - /// - /// An optional string for which the backing buffer is to be retrieved. Can be . - /// - /// An optional pointer to a . If - /// is passed for , then it is ignored. If - /// is a valid pointer to a , - /// and string is a valid , then on successful - /// completion the function sets the value pointed to by to the number of Unicode characters in the backing - /// buffer for (including embedded null - /// characters, but excluding the terminating null). If is a valid pointer to a , and - /// is , then the value - /// pointed to by is set to 0. - /// - /// A pointer to the buffer that provides the backing store for , or the empty string if is or the empty string. - /// WindowsGetStringRawBuffer function (winstring.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - ushort* WindowsGetStringRawBuffer(HSTRING @string, uint* length); - - /// - /// Compares two specified objects and returns an integer that indicates their relative position in a sort order. - /// - /// The first string to compare. - /// The second string to compare. - /// A value that indicates the lexical relationship between and . - /// - /// This function can return one of these values. - /// - /// - /// Return code - /// Description - /// - /// - /// S_OK - /// The comparison was successful. - /// - /// - /// E_INVALIDARG - /// is . - /// - /// - /// - /// WindowsCompareStringOrdinal function (winstring.h) -#if NET8_0_OR_GREATER - [LibraryImport("combase")] -#else - [DllImport("combase", ExactSpelling = true)] -#endif - public static -#if NET8_0_OR_GREATER - partial -#else - extern -#endif - int WindowsCompareStringOrdinal(HSTRING string1, HSTRING string2, int* result); -} diff --git a/src/Shmuelie.WinRTServer/Windows/winrt/wrl/client/ComPtr.cs b/src/Shmuelie.WinRTServer/Windows/winrt/wrl/client/ComPtr.cs index e0f8553..97640ef 100644 --- a/src/Shmuelie.WinRTServer/Windows/winrt/wrl/client/ComPtr.cs +++ b/src/Shmuelie.WinRTServer/Windows/winrt/wrl/client/ComPtr.cs @@ -1,6 +1,8 @@ using System; using System.Runtime.CompilerServices; -using static Shmuelie.Interop.Windows.S; +using Windows.Win32; +using Windows.Win32.Foundation; +using Windows.Win32.System.Com; namespace Shmuelie.Interop.Windows; @@ -89,52 +91,68 @@ public void Attach(T* other) /// Increments the reference count for the current COM object, if any, and copies its address to a target raw pointer. /// /// The target raw pointer to copy the address of the current COM object to. - /// This method always returns . - public readonly int CopyTo(T** ptr) + /// This method always returns . + public readonly HRESULT CopyTo(T** ptr) { InternalAddRef(); *ptr = ptr_; - return S.S_OK; + return HRESULT.S_OK; } /// /// Increments the reference count for the current COM object, if any, and copies its address to a target raw pointer. /// /// The target raw pointer to copy the address of the current COM object to. - /// This method always returns . - public readonly int CopyTo(ref T* ptr) + /// This method always returns . + public readonly HRESULT CopyTo(ref T* ptr) { InternalAddRef(); ptr = ptr_; - return S.S_OK; + return HRESULT.S_OK; } /// /// Converts the current COM object reference to a given interface type and assigns that to a target raw pointer. /// /// The target raw pointer to copy the address of the current COM object to. - /// The result of for the target type . - public readonly int CopyTo(U** ptr) + /// The result of for the target type . + public readonly HRESULT CopyTo(U** ptr) where U : unmanaged +#if !NETSTANDARD + , IComIID +#endif { +#if NETSTANDARD return ((IUnknown*)ptr_)->QueryInterface(Windows.__uuidof(), (void**)ptr); +#else + Guid iid = U.Guid; + return ((IUnknown*)ptr_)->QueryInterface(&iid, (void**)ptr); +#endif } /// /// Converts the current COM object reference to a given interface type and assigns that to a target raw pointer. /// /// The target raw pointer to copy the address of the current COM object to. - /// The result of for the target type . - public readonly int CopyTo(ref U* ptr) + /// The result of for the target type . + public readonly HRESULT CopyTo(ref U* ptr) where U : unmanaged +#if !NETSTANDARD + , IComIID +#endif { void** tmp = null; - int @ref = ((IUnknown*)ptr_)->QueryInterface(Windows.__uuidof(), tmp); +#if NETSTANDARD + HRESULT @ref = ((IUnknown*)ptr_)->QueryInterface(Windows.__uuidof(), tmp); +#else + Guid iid = U.Guid; + HRESULT @ref = ((IUnknown*)ptr_)->QueryInterface(&iid, tmp); +#endif ptr = (U*)tmp; @@ -146,7 +164,7 @@ public readonly int CopyTo(ref U* ptr) /// /// The IID indicating the interface type to convert the COM object reference to. /// The target raw pointer to copy the address of the current COM object to. - /// The result of for the target IID. + /// The result of for the target IID. public readonly int CopyTo(Guid* riid, void** ptr) { return ((IUnknown*)ptr_)->QueryInterface(riid, ptr);