[Settings] move the DLL imports to NativeMethods file (#24381)

* move the DLL imports to NativeMethods file

* Change the DLL import from public to internal.
This commit is contained in:
sosssego
2023-03-17 18:14:23 +00:00
committed by GitHub
parent 9d7373467d
commit dbe52d3d52
2 changed files with 9 additions and 9 deletions

View File

@@ -38,6 +38,12 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
[DllImport("user32.dll")] [DllImport("user32.dll")]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("shell32.dll")]
internal static extern IntPtr SHBrowseForFolderW(ref ShellGetFolder.BrowseInformation browseInfo);
[DllImport("shell32.dll")]
internal static extern int SHGetPathFromIDListW(IntPtr pidl, IntPtr pszPath);
#pragma warning disable CA1401 // P/Invokes should not be visible #pragma warning disable CA1401 // P/Invokes should not be visible
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool ShowWindow(System.IntPtr hWnd, int nCmdShow); public static extern bool ShowWindow(System.IntPtr hWnd, int nCmdShow);
@@ -59,6 +65,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool FreeLibrary(IntPtr hModule); public static extern bool FreeLibrary(IntPtr hModule);
#pragma warning restore CA1401 // P/Invokes should not be visible #pragma warning restore CA1401 // P/Invokes should not be visible
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]

View File

@@ -5,18 +5,11 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using static Microsoft.PowerToys.Settings.UI.Helpers.ShellGetFolder;
namespace Microsoft.PowerToys.Settings.UI.Helpers namespace Microsoft.PowerToys.Settings.UI.Helpers
{ {
public class ShellGetFolder public class ShellGetFolder
{ {
[DllImport("shell32.dll")]
private static extern IntPtr SHBrowseForFolderW(ref BrowseInformation browseInfo);
[DllImport("shell32.dll")]
private static extern int SHGetPathFromIDListW(IntPtr pidl, IntPtr pszPath);
public delegate int BrowseCallbackProc(IntPtr hwnd, int msg, IntPtr lp, IntPtr wp); public delegate int BrowseCallbackProc(IntPtr hwnd, int msg, IntPtr lp, IntPtr wp);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
@@ -51,8 +44,8 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
try try
{ {
pidl = SHBrowseForFolderW(ref browseInfo); pidl = NativeMethods.SHBrowseForFolderW(ref browseInfo);
if (SHGetPathFromIDListW(pidl, bufferAddress) == 0) if (NativeMethods.SHGetPathFromIDListW(pidl, bufferAddress) == 0)
{ {
return null; return null;
} }