Skip to content

Commit 7fb3639

Browse files
Tests
1 parent c00f9ec commit 7fb3639

11 files changed

+418
-3
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,4 @@ MigrationBackup/
362362
# Fody - auto-generated XML schema
363363
FodyWeavers.xsd
364364

365-
XamlIslands/FullTrustUWP/Core/*
365+
# XamlIslands/FullTrustUWP/Core/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Windows.ApplicationModel;
3+
using Windows.ApplicationModel.Core;
4+
using Windows.Foundation;
5+
using Windows.Foundation.Collections;
6+
7+
namespace FullTrustUWP.Core.Activation
8+
{
9+
public static class CoreApplicationActivator
10+
{
11+
public static ICoreApplication ActivateCoreApplication()
12+
{
13+
Guid IID_ICoreApplication = new Guid("0aacf7a4-5e1d-49df-8034-fb6a68bc5ed1");
14+
InteropHelper.GetActivationFactory("Windows.ApplicationModel.Core.CoreApplication", ref IID_ICoreApplication, out var factory);
15+
return factory as ICoreApplication;
16+
}
17+
18+
public interface ICoreApplication
19+
{
20+
CoreApplicationView GetCurrentView();
21+
void Run(IFrameworkViewSource viewSource);
22+
void RunWithActivationFactories(IGetActivationFactory activationFactoryCallback);
23+
24+
string Id { get; }
25+
IPropertySet Properties { get; }
26+
27+
event EventHandler<object> Resuming;
28+
event EventHandler<SuspendingEventArgs> Suspending;
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Windows.ApplicationModel.Core;
4+
using Windows.UI.Core;
5+
using Windows.UI.ViewManagement;
6+
using Windows.UI.WindowManagement;
7+
using static FullTrustUWP.Core.InteropHelper;
8+
9+
namespace FullTrustUWP.Core.Activation
10+
{
11+
public static class CoreWindowActivator
12+
{
13+
public enum WindowType : long
14+
{
15+
IMMERSIVE_DOCK = 1,
16+
IMMERSIVE_HOSTED,
17+
IMMERSIVE_BODY_ACTIVE = 4,
18+
IMMERSIVE_DOCK_ACTIVE,
19+
NOT_IMMERSIVE
20+
}
21+
22+
private delegate int PrivateCreateCoreWindow_Sig(WindowType windowType, [MarshalAs(UnmanagedType.BStr)] string windowTitle, int x, int y, uint width, uint height, uint dwAttributes, IntPtr hOwnerWindow, Guid riid, out ICoreWindowInterop windowRef);
23+
private static PrivateCreateCoreWindow_Sig PrivateCreateCoreWindow_Ref;
24+
25+
public static CoreWindow CreateCoreWindow(WindowType windowType, string windowTitle, IntPtr hOwnerWindow, int x = 0, int y = 0, uint width = 10, uint height = 10, uint dwAttributes = 0)
26+
{
27+
if (PrivateCreateCoreWindow_Ref == null)
28+
PrivateCreateCoreWindow_Ref = DynamicLoad<PrivateCreateCoreWindow_Sig>("windows.ui.dll", 0x5dc);
29+
30+
Marshal.ThrowExceptionForHR(PrivateCreateCoreWindow_Ref(windowType, windowTitle, x, y, width, height, dwAttributes, hOwnerWindow, typeof(ICoreWindowInterop).GUID, out ICoreWindowInterop windowRef));
31+
return windowRef as object as CoreWindow;
32+
}
33+
34+
private delegate int CreateCoreApplicationViewTitleBar_Sig(CoreWindow titleBarClientAdapter, IntPtr hWnd, out CoreApplicationViewTitleBar titleBar);
35+
private static CreateCoreApplicationViewTitleBar_Sig CreateCoreApplicationViewTitleBar_Ref;
36+
37+
public static CoreApplicationViewTitleBar CreateCoreApplicationViewTitleBar(CoreWindow coreWindow, IntPtr hWnd)
38+
{
39+
if (CreateCoreApplicationViewTitleBar_Ref == null)
40+
CreateCoreApplicationViewTitleBar_Ref = DynamicLoad<CreateCoreApplicationViewTitleBar_Sig>("twinapi.appcore.dll", 501);
41+
42+
Marshal.ThrowExceptionForHR(CreateCoreApplicationViewTitleBar_Ref(coreWindow, hWnd, out var titleBar));
43+
return titleBar;
44+
}
45+
46+
[DllImport("twinapi.appcore.dll", SetLastError = true)]
47+
private static extern int CreateCoreApplicationViewTitleBar(CoreWindow titleBarClientAdapter, IntPtr hWnd, out CoreApplicationViewTitleBar titleBar);
48+
49+
[DllImport("twinapi.appcore", SetLastError = true)]
50+
private static extern int CreateApplicationViewTitleBar(AppWindow titleBarClientAdapter, IntPtr hWnd, out ApplicationViewTitleBar titleBar);
51+
}
52+
53+
[ComImport, Guid(Const.IID_ICoreWindowInterop)]
54+
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
55+
public interface ICoreWindowInterop
56+
{
57+
IntPtr WindowHandle { get; }
58+
bool MessageHandled { get; }
59+
}
60+
61+
[InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
62+
[Guid("CD292360-2763-4085-8A9F-74B224A29175")]
63+
public interface ICoreWindowFactory
64+
{
65+
void CreateCoreWindow([MarshalAs(UnmanagedType.HString)] string windowTitle, out CoreWindow window);
66+
bool WindowReuseAllowed { get; }
67+
}
68+
69+
public sealed class CoreWindowFactory : ICoreWindowFactory
70+
{
71+
public bool WindowReuseAllowed => true;
72+
73+
public void CreateCoreWindow([MarshalAs(UnmanagedType.HString)] string windowTitle, out CoreWindow window)
74+
{
75+
window = CoreWindowActivator.CreateCoreWindow(
76+
CoreWindowActivator.WindowType.IMMERSIVE_BODY_ACTIVE,
77+
windowTitle,
78+
IntPtr.Zero,
79+
width: 1024,
80+
height: 768
81+
);
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using FullTrustUWP.Core.Activation;
2+
using System.Runtime.InteropServices;
3+
using Windows.ApplicationModel.Activation;
4+
5+
namespace FullTrustUWP.Core
6+
{
7+
public sealed class AppxActivator
8+
{
9+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
10+
private static extern bool SetDllDirectory(string lpPathName);
11+
}
12+
13+
[InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
14+
[Guid("92696c00-7578-48e1-ac1a-2ca909e2c8cf")]
15+
public interface IActivatableApplication
16+
{
17+
void Activate(ref ICoreWindowFactory windowFactory, [MarshalAs(UnmanagedType.HString)] string serverName, ref IActivatedEventArgs eventArgs);
18+
}
19+
20+
public sealed class ActivatedEventArgsImpl : IActivatedEventArgs, IPrelaunchActivatedEventArgs, ILaunchActivatedEventArgs
21+
{
22+
public ActivationKind Kind => ActivationKind.Launch;
23+
24+
public ApplicationExecutionState PreviousExecutionState => ApplicationExecutionState.NotRunning;
25+
26+
public SplashScreen SplashScreen => null;
27+
28+
public bool PrelaunchActivated => false;
29+
30+
public string Arguments => "";
31+
32+
public string TileId => "";
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.InteropServices;
4+
using static FullTrustUWP.Core.InteropHelper;
5+
6+
namespace FullTrustUWP.Core
7+
{
8+
internal static class AppxActivatorTest
9+
{
10+
11+
[DllImport("daxexec.dll", SetLastError = true)]
12+
public static extern IntPtr TryActivateDesktopAppXApplication(DesktopAppxActivationParams activationParams);
13+
14+
public enum DesktopAppxActivationParams
15+
{
16+
None = 0x0
17+
}
18+
19+
public struct DESKTOP_APPX_ACTIVATION_RESULT { }
20+
21+
public static void Test()
22+
{
23+
int hRes;
24+
IActivationFactory appActivationFactory;
25+
Guid guid = new(Const.IID_ICoreApplicationPrivate2);
26+
ThrowOnError(GetActivationFactory("Windows.ApplicationModel.Core.CoreApplication", ref guid, out appActivationFactory));
27+
ICoreApplicationPrivate2 app = appActivationFactory as ICoreApplicationPrivate2;
28+
29+
guid = new(Const.IID_ICoreWindowStatic);
30+
ThrowOnError(GetActivationFactory("Windows.UI.Core.CoreWindow", ref guid, out appActivationFactory));
31+
32+
Debugger.Break();
33+
}
34+
}
35+
36+
[Guid(Const.IID_ICoreApplicationPrivate2), InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
37+
public interface ICoreApplicationPrivate2
38+
{
39+
40+
}
41+
42+
[Guid(Const.IID_ICoreWindowStatic), InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
43+
public interface ICoreWindowStatic
44+
{
45+
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using static FullTrustUWP.Core.InteropHelper;
4+
5+
namespace FullTrustUWP.Core
6+
{
7+
public static class CapabilityChecker
8+
{
9+
// CapabilityCheck(0i64, L"shellExperienceComposer", &v58)
10+
public static bool HasCapability(string capability)
11+
{
12+
CapabilityCheck(IntPtr.Zero, capability, out bool result);
13+
ThrowOnError();
14+
return result;
15+
}
16+
17+
[DllImport("sechost.dll", SetLastError = true)]
18+
private static extern void CapabilityCheck(IntPtr ptr, string capability, out bool result);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Runtime.InteropServices;
4+
5+
namespace FullTrustUWP.Core
6+
{
7+
public static class InteropHelper
8+
{
9+
#region ThrowOnError
10+
public static void ThrowOnError() => ThrowOnError(Marshal.GetLastWin32Error());
11+
12+
public static void ThrowOnError(int error)
13+
{
14+
if (error != 0)
15+
throw new Win32Exception(error);
16+
}
17+
#endregion
18+
19+
#region DynamicLoad
20+
public static T DynamicLoad<T>(string libraryName, int ordinal) where T : Delegate
21+
{
22+
IntPtr hLib = LoadLibrary(libraryName);
23+
IntPtr hProc = GetProcAddress(hLib, ordinal);
24+
return Marshal.GetDelegateForFunctionPointer<T>(hProc);
25+
}
26+
27+
public static T DynamicLoad<T>(string libraryName, string procName) where T : Delegate
28+
{
29+
IntPtr hLib = LoadLibrary(libraryName);
30+
IntPtr hProc = GetProcAddress(hLib, procName);
31+
return Marshal.GetDelegateForFunctionPointer<T>(hProc);
32+
}
33+
34+
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
35+
private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
36+
37+
[DllImport("kernel32", SetLastError = true)]
38+
private static extern IntPtr GetProcAddress(IntPtr hModule, int ordinal);
39+
40+
[DllImport("kernel32", SetLastError = true)]
41+
private static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
42+
#endregion
43+
44+
[DllImport("combase.dll", EntryPoint = "RoGetActivationFactory", CharSet = CharSet.Unicode, SetLastError = true), PreserveSig]
45+
public static extern int GetActivationFactory([MarshalAs(UnmanagedType.HString)] string activatableClassId, ref Guid iid, out IActivationFactory factory);
46+
}
47+
48+
[Guid("00000035-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
49+
public interface IActivationFactory
50+
{
51+
IntPtr ActivateInstance();
52+
}
53+
54+
public static class Const
55+
{
56+
public const string IID_ICoreApplicationPrivate2 = "6090202d-2843-4ba5-9b0d-fc88eecd9ce5";
57+
public const string IID_ICoreWindowStatic = "4d239005-3c2a-41b1-9022-536bb9cf93b1";
58+
public const string IID_ICoreWindowInterop = "45d64a29-a63e-4cb6-b498-5781d298cb4f";
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace FullTrustUWP.Core
6+
{
7+
public sealed class PackageIdentity
8+
{
9+
public PackageIdentity() { }
10+
11+
public void SetCurrentPackageIdentity()
12+
{
13+
14+
}
15+
}
16+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using FullTrustUWP.Core.Activation;
2+
using System;
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
using System.Windows.Forms;
6+
using Windows.ApplicationModel.Activation;
7+
using Windows.UI.Core;
8+
using Windows.UI.WindowManagement;
9+
10+
namespace FullTrustUWP.Core
11+
{
12+
class Tests
13+
{
14+
static async void Test_AppWindow()
15+
{
16+
var instance = await AppWindow.TryCreateAsync();
17+
// var app = CoreApplication.CreateNewView();
18+
Debugger.Break();
19+
}
20+
21+
static void Test_CreateCoreApplicationViewTitleBar()
22+
{
23+
Form form = new();
24+
form.Show();
25+
26+
var titleBar = CoreWindowActivator.CreateCoreApplicationViewTitleBar(null, form.Handle /*windowInterop.WindowHandle*/);
27+
var x = titleBar.Height;
28+
29+
Application.Run();
30+
}
31+
32+
static void Test_CreateCoreWindow()
33+
{
34+
Form form = new();
35+
form.Show();
36+
37+
CoreWindow window = CoreWindowActivator.CreateCoreWindow(CoreWindowActivator.WindowType.IMMERSIVE_HOSTED, "TestWindow", form.Handle);
38+
// CoreWindow window = CoreWindowActivator.CreateCoreWindow(CoreWindowActivator.WindowType.IMMERSIVE_BODY_ACTIVE, "TestWindow", IntPtr.Zero);
39+
window.Activate();
40+
}
41+
42+
[DllImport("daxexec.dll", SetLastError = true)]
43+
public static extern int TryActivateDesktopAppXApplication(string appUserModelId, out int processId);
44+
45+
[StructLayout(LayoutKind.Sequential)]
46+
public struct AppxActivationParams
47+
{
48+
public object _1;
49+
public string launchMode; // Windows.Launch // Windows.Protocol // Windows.File // Windows.ShareTarget // Windows.StartupTask
50+
public IActivatedEventArgs activatedEventArgs; // cf651713-cd08-4fd8-b697-a281b6544e2e
51+
public object _2;
52+
public object _3;
53+
public object _4;
54+
public object _5;
55+
public object _6;
56+
public object _7;
57+
public bool _8;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)