Skip to content

Commit

Permalink
直接使用指针生成 PWSTR
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Aug 20, 2024
1 parent 1f2f792 commit a305ede
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion CoreAppUWP/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Windows.Graphics;
using Windows.UI.Core;


// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

Expand Down
11 changes: 4 additions & 7 deletions CoreAppUWP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ private static unsafe bool IsPackagedApp
PWSTR str = new();
_ = PInvoke.GetCurrentPackageFullName(ref length, str);

char[] array = new char[length];
fixed (char* ptr = array)
{
str = new(ptr);
WIN32_ERROR result = PInvoke.GetCurrentPackageFullName(ref length, str);
return result != WIN32_ERROR.APPMODEL_ERROR_NO_PACKAGE;
}
char* ptr = stackalloc char[(int)length];
str = new(ptr);
WIN32_ERROR result = PInvoke.GetCurrentPackageFullName(ref length, str);
return result != WIN32_ERROR.APPMODEL_ERROR_NO_PACKAGE;
}
}

Expand Down

0 comments on commit a305ede

Please sign in to comment.