summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2017-09-03 17:46:11 +0100
committersr55 <[email protected]>2017-09-03 17:46:11 +0100
commitaf03073a0d59b5568608eea5fc85fababca95f0d (patch)
tree667adda6eeb24014bd4197f0fd6bb7784a3d3768 /win
parent8769cf1221a170ce69e10ac2e7d50a168665faf0 (diff)
WinGui: Fix UwpDetect
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrakeWPF/Utilities/UwpDetect.cs16
1 files changed, 12 insertions, 4 deletions
diff --git a/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs b/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs
index 068165924..827b025d0 100644
--- a/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs
+++ b/win/CS/HandBrakeWPF/Utilities/UwpDetect.cs
@@ -12,11 +12,14 @@ namespace HandBrakeWPF.Utilities
{
using System;
using System.Runtime.InteropServices;
+ using System.Text;
public class UwpDetect
{
[DllImport("kernel32.dll")]
- static extern int GetCurrentPackageFullName(ref int length, IntPtr fullName);
+ static extern int GetCurrentPackageFullName(ref int length, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder fullName);
+
+ private const int APPMODEL_ERROR_NO_PACKAGE = 15700;
public static bool IsUWP()
{
@@ -26,10 +29,15 @@ namespace HandBrakeWPF.Utilities
}
int length = 0;
- IntPtr name = IntPtr.Zero;
- GetCurrentPackageFullName(ref length, name); // Only available in 6.2 or later.
+ StringBuilder packageName = new StringBuilder(1024);
+
+ int result = GetCurrentPackageFullName(ref length, packageName); // Only available in 6.2 or later.
+ if (result == APPMODEL_ERROR_NO_PACKAGE)
+ {
+ return false;
+ }
- if (length > 0)
+ if (packageName.ToString().Trim().Length > 0)
{
return true;
}