Skip to content

Commit

Permalink
Use GeneratedDllImport in Microsoft.Win32.SystemEvents (#61609)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Nov 15, 2021
1 parent 3b71d3b commit d471a03
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32, ExactSpelling = true)]
[GeneratedDllImport(Libraries.Kernel32, ExactSpelling = true)]
[SuppressGCTransition]
public static extern int GetCurrentThreadId();
public static partial int GetCurrentThreadId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32, EntryPoint = "GetModuleHandleW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern IntPtr GetModuleHandle(string? moduleName);
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "GetModuleHandleW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static partial IntPtr GetModuleHandle(string? moduleName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false)]
public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);
[GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Ansi)]
public static partial IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);

[DllImport(Libraries.Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Ansi)]
public static partial IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static partial class Kernel32
{
internal delegate bool ConsoleCtrlHandlerRoutine(int controlType);

[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool SetConsoleCtrlHandler(ConsoleCtrlHandlerRoutine handler, bool addOrRemove);
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
internal static partial bool SetConsoleCtrlHandler(ConsoleCtrlHandlerRoutine handler, bool addOrRemove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern IntPtr CreateWindowExW(
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
public static partial IntPtr CreateWindowExW(
int exStyle,
string lpszClassName,
string lpszWindowName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr DefWindowProcW(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr DefWindowProcW(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern bool DestroyWindow(IntPtr hWnd);
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static partial bool DestroyWindow(IntPtr hWnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern int DispatchMessageW([In] ref MSG msg);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial int DispatchMessageW(ref MSG msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet=CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr FindWindowW(string lpClassName, string lpWindowName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern bool GetClassInfoW(IntPtr hInst, string lpszClass, ref WNDCLASS wc);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial bool GetClassInfoW(IntPtr hInst, string lpszClass, ref WNDCLASS wc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
internal static extern IntPtr GetProcessWindowStation();
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
internal static partial IntPtr GetProcessWindowStation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern unsafe bool GetUserObjectInformationW(IntPtr hObj, int nIndex, void* pvBuffer, uint nLength, ref uint lpnLengthNeeded);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
public static unsafe partial bool GetUserObjectInformationW(IntPtr hObj, int nIndex, void* pvBuffer, uint nLength, ref uint lpnLengthNeeded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern bool IsWindow(IntPtr hWnd);
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static partial bool IsWindow(IntPtr hWnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern bool KillTimer(IntPtr hwnd, IntPtr idEvent);
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static partial bool KillTimer(IntPtr hwnd, IntPtr idEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern int MsgWaitForMultipleObjectsEx(int nCount, IntPtr pHandles, int dwMilliseconds, int dwWakeMask, int dwFlags);
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static partial int MsgWaitForMultipleObjectsEx(int nCount, IntPtr pHandles, int dwMilliseconds, int dwWakeMask, int dwFlags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern bool PeekMessageW([In, Out] ref MSG msg, IntPtr hwnd, int msgMin, int msgMax, int remove);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial bool PeekMessageW(ref MSG msg, IntPtr hwnd, int msgMin, int msgMax, int remove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern short RegisterClassW(ref WNDCLASS wc);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
public static partial short RegisterClassW(ref WNDCLASS wc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern int RegisterWindowMessageW(string msg);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial int RegisterWindowMessageW(string msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr SendMessageW(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr SendMessageW(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr SendMessageW(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr SetClassLongW(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr SetClassLongW(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr SetClassLongPtrW(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr SetClassLongPtrW(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern IntPtr SetTimer(IntPtr hWnd, IntPtr nIDEvent, int uElapse, IntPtr lpTimerProc);
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static partial IntPtr SetTimer(IntPtr hWnd, IntPtr nIDEvent, int uElapse, IntPtr lpTimerProc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr SetWindowLongW(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr SetWindowLongW(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
public static extern bool TranslateMessage([In, Out] ref MSG msg);
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static partial bool TranslateMessage(ref MSG msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
public static extern short UnregisterClassW(string lpClassName, IntPtr hInstance);
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
public static partial short UnregisterClassW(string lpClassName, IntPtr hInstance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetFrameworkMinimum)</TargetFrameworks>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDllImportGenerator>true</EnableDllImportGenerator>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Expand Down

0 comments on commit d471a03

Please sign in to comment.