Skip to content

Commit

Permalink
Fix lookup for factories
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuelie committed Dec 17, 2023
1 parent e33dac2 commit 5866423
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Shmuelie.WinRTServer/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ RoInitialize
RoRegisterActivationFactories
RoRevokeActivationFactories
S_FALSE
GLOBALOPT_RO_FLAGS
GLOBALOPT_RO_FLAGS
WindowsGetStringRawBuffer
2 changes: 1 addition & 1 deletion src/Shmuelie.WinRTServer/WinRtServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private unsafe HRESULT ActivationFactoryCallback(HSTRING activatableClassId, IAc
return HRESULT.E_INVALIDARG;
}

if (!factories.TryGetValue(activatableClassId.ToString(), out BaseActivationFactory? managedFactory))
if (!factories.TryGetValue(activatableClassId.AsString(), out BaseActivationFactory? managedFactory))
{
factory = null;
return HRESULT.E_NOINTERFACE;
Expand Down
24 changes: 24 additions & 0 deletions src/Shmuelie.WinRTServer/Windows/winrt/HSTRING.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Windows.Win32.Foundation;
using Windows.Win32.System.WinRT;
using static Windows.Win32.PInvoke;

namespace Shmuelie.Interop.Windows;

internal static class HSTRING_
{
#if !NETSTANDARD
[System.Runtime.Versioning.SupportedOSPlatform("windows8.0")]
#endif
public unsafe static string AsString(this HSTRING @this)
{
if (@this.IsNull)
{
return string.Empty;
}

uint characterCount;
PCWSTR characters = WindowsGetStringRawBuffer(@this, &characterCount);

return characters.ToString();
}
}

0 comments on commit 5866423

Please sign in to comment.