Skip to content

Commit 4452a33

Browse files
committed
Use explicit types and nint/nuint in APIs
1 parent abea063 commit 4452a33

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

src/SecondaryClick/Gestures/Modifiers/ModifiersGestureRecognizer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private void OnMouseDown(object? sender, MouseEventExtArgs e)
141141
if (!_enabled || _suppressInjected)
142142
return;
143143

144-
var pressedModifiers = GetPressedActivationModifiers();
144+
GestureModifiers pressedModifiers = GetPressedActivationModifiers();
145145
if (pressedModifiers == GestureModifiers.None)
146146
return;
147147

@@ -246,7 +246,7 @@ private bool IsActivationModifierPressed()
246246
/// <returns>A combination of flags representing the pressed modifiers.</returns>
247247
private GestureModifiers GetPressedActivationModifiers()
248248
{
249-
var modifiers = GestureModifiers.None;
249+
GestureModifiers modifiers = GestureModifiers.None;
250250

251251
if (_activationModifiers.HasFlag(GestureModifiers.Alt) && IsAltPressed())
252252
{
@@ -331,7 +331,7 @@ private static bool IsKeyDown(int virtualKey)
331331
private void InjectAltKeyUp(Keys keyCode)
332332
{
333333
// Replay the suppressed Alt key-up so Windows clears the modifier state.
334-
var vk = keyCode switch
334+
User32.VK vk = keyCode switch
335335
{
336336
Keys.LMenu => User32.VK.VK_LMENU,
337337
Keys.RMenu => User32.VK.VK_RMENU,

src/SecondaryClick/Gestures/Touchpads/PrecisionTouchpadSPISettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static bool IsWritable
3232
/// <returns>True if the operation succeeded, false otherwise.</returns>
3333
public static bool SetTwoFingerTapRightClickEnabled(bool enabled)
3434
{
35-
if (!TryGetParameters(out var p))
35+
if (!TryGetParameters(out TOUCHPAD_PARAMETERS_V1 p))
3636
return false;
3737

3838
p.TwoFingerTapEnabled = enabled;
@@ -46,7 +46,7 @@ public static bool SetTwoFingerTapRightClickEnabled(bool enabled)
4646
/// <returns>True if the operation succeeded, false otherwise.</returns>
4747
public static bool SetRightClickZoneEnabled(bool enabled)
4848
{
49-
if (!TryGetParameters(out var p))
49+
if (!TryGetParameters(out TOUCHPAD_PARAMETERS_V1 p))
5050
return false;
5151

5252
p.RightClickZoneEnabled = enabled;

src/SecondaryClick/TrayIconManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public static void ShowNotification(string title, string content, bool isError =
332332
Action? clickEvent = null,
333333
Action? closeEvent = null)
334334
{
335-
var icon = GetInstance()._icon;
335+
TrayIconHost icon = GetInstance()._icon;
336336
icon.ShowBalloonTip(timeout, title, content, isError ? TrayToolTipIcon.Error : TrayToolTipIcon.Info);
337337
icon.BalloonTipClicked += OnIconOnBalloonTipClicked;
338338
icon.BalloonTipClosed += OnIconOnBalloonTipClosed;

src/SecondaryClick/WinApi/Advapi32.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static class Advapi32
1010
/// <summary>
1111
/// Predefined handle to the HKEY_CURRENT_USER root key.
1212
/// </summary>
13-
public static readonly UIntPtr HKEY_CURRENT_USER = (UIntPtr)0x80000001u;
13+
public static readonly nuint HKEY_CURRENT_USER = 0x80000001u;
1414

1515
/// <summary>
1616
/// Access right for querying key value data.
@@ -53,11 +53,11 @@ internal static class Advapi32
5353
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
5454
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
5555
public static extern int RegOpenKeyEx(
56-
UIntPtr hKey,
56+
nuint hKey,
5757
string lpSubKey,
5858
int ulOptions,
5959
int samDesired,
60-
out IntPtr phkResult);
60+
out nint phkResult);
6161

6262
/// <summary>
6363
/// Creates or opens the specified registry key.
@@ -68,20 +68,20 @@ public static extern int RegOpenKeyEx(
6868
/// <param name="lpClass">The user-defined class type for this key. Typically null.</param>
6969
/// <param name="dwOptions">Special options for key creation. Typically zero.</param>
7070
/// <param name="samDesired">The access rights requested for the key.</param>
71-
/// <param name="lpSecurityAttributes">Security descriptor pointer. Typically IntPtr.Zero.</param>
71+
/// <param name="lpSecurityAttributes">Security descriptor pointer. Typically 0.</param>
7272
/// <param name="phkResult">When successful, receives a handle to the opened or created key.</param>
7373
/// <param name="lpdwDisposition">Receives status indicating whether key was created or opened.</param>
7474
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
7575
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
7676
public static extern int RegCreateKeyEx(
77-
UIntPtr hKey,
77+
nuint hKey,
7878
string lpSubKey,
7979
int Reserved,
8080
string? lpClass,
8181
uint dwOptions,
8282
int samDesired,
83-
IntPtr lpSecurityAttributes,
84-
out IntPtr phkResult,
83+
nint lpSecurityAttributes,
84+
out nint phkResult,
8585
out uint lpdwDisposition);
8686

8787
/// <summary>
@@ -96,7 +96,7 @@ public static extern int RegCreateKeyEx(
9696
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
9797
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
9898
public static extern int RegSetValueEx(
99-
IntPtr hKey,
99+
nint hKey,
100100
string lpValueName,
101101
int Reserved,
102102
uint dwType,
@@ -115,7 +115,7 @@ public static extern int RegSetValueEx(
115115
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
116116
[DllImport("advapi32.dll", SetLastError = true)]
117117
public static extern int RegSetValueEx(
118-
IntPtr hKey,
118+
nint hKey,
119119
string lpValueName,
120120
int Reserved,
121121
uint dwType,
@@ -134,7 +134,7 @@ public static extern int RegSetValueEx(
134134
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
135135
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
136136
public static extern int RegQueryValueEx(
137-
IntPtr hKey,
137+
nint hKey,
138138
string lpValueName,
139139
int lpReserved,
140140
out uint lpType,
@@ -149,7 +149,7 @@ public static extern int RegQueryValueEx(
149149
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
150150
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
151151
public static extern int RegDeleteValue(
152-
IntPtr hKey,
152+
nint hKey,
153153
string lpValueName);
154154

155155
/// <summary>
@@ -158,5 +158,5 @@ public static extern int RegDeleteValue(
158158
/// <param name="hKey">A handle to an open registry key.</param>
159159
/// <returns>Win32 error code. ERROR_SUCCESS indicates success.</returns>
160160
[DllImport("advapi32.dll", SetLastError = true)]
161-
public static extern int RegCloseKey(IntPtr hKey);
162-
}
161+
public static extern int RegCloseKey(nint hKey);
162+
}

src/SecondaryClick/WinApi/RegistryApi.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static bool TryReadRawCurrentUser(string subKeyPath, string valueName, ou
3333
subKeyPath,
3434
0,
3535
Advapi32.KEY_QUERY_VALUE,
36-
out IntPtr keyHandle);
36+
out nint keyHandle);
3737

3838
if (openResult != Win32Error.ERROR_SUCCESS)
3939
return false;
@@ -131,8 +131,8 @@ public static bool SetDwordCurrentUser(string subKeyPath, string valueName, int
131131
null,
132132
0,
133133
Advapi32.KEY_SET_VALUE,
134-
IntPtr.Zero,
135-
out IntPtr keyHandle,
134+
0,
135+
out nint keyHandle,
136136
out _);
137137

138138
if (createResult != Win32Error.ERROR_SUCCESS)
@@ -173,8 +173,8 @@ public static bool SetStringCurrentUser(string subKeyPath, string valueName, str
173173
null,
174174
0,
175175
Advapi32.KEY_SET_VALUE,
176-
IntPtr.Zero,
177-
out IntPtr keyHandle,
176+
0,
177+
out nint keyHandle,
178178
out _);
179179

180180
if (createResult != Win32Error.ERROR_SUCCESS)
@@ -212,7 +212,7 @@ public static bool DeleteValueCurrentUser(string subKeyPath, string valueName)
212212
subKeyPath,
213213
0,
214214
Advapi32.KEY_SET_VALUE,
215-
out IntPtr keyHandle);
215+
out nint keyHandle);
216216

217217
if (openResult == Win32Error.ERROR_FILE_NOT_FOUND)
218218
return true;

0 commit comments

Comments
 (0)