Skip to content

Commit 083e912

Browse files
committed
Fix some Win32 API definitions
1 parent c84d292 commit 083e912

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/BizHawk.Client.EmuHawk/CustomControls/FolderBrowserDialogEx.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ int Callback(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData)
6767
browseOptions &= ~BROWSEINFOW.FLAGS.NewDialogStyle;
6868
}
6969

70-
pszDisplayName = Marshal.AllocCoTaskMem(Win32Imports.MAX_PATH * sizeof(char));
70+
const int BUF_SIZE_BYTES = (int) Win32Imports.MAX_PATH * sizeof(char);
71+
pszDisplayName = Marshal.AllocCoTaskMem(BUF_SIZE_BYTES);
7172
var bi = new BROWSEINFOW
7273
{
7374
hwndOwner = hWndOwner,

src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static string ResolveShortcut(string filename)
3333
((ShellLinkImports.IShellLinkW*)link)->Resolve(hwnd, 0);
3434
#endif
3535

36-
((ShellLinkImports.IShellLinkW*)link)->GetPath(out var path, Win32Imports.MAX_PATH + 1, 0);
36+
((ShellLinkImports.IShellLinkW*) link)->GetPath(out var path, (int) Win32Imports.MAX_PATH + 1, 0);
3737
return path;
3838
}
3939
}

src/BizHawk.Common/Win32/CWDHacks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static Exception GetExceptionForFailure()
2323
return new InvalidOperationException("GetCurrentDirectoryW returned 0!", ex);
2424
}
2525

26-
const int STARTING_BUF_SIZE = Win32Imports.MAX_PATH + 1;
26+
const int STARTING_BUF_SIZE = (int) Win32Imports.MAX_PATH + 1;
2727
var startingBuffer = stackalloc char[STARTING_BUF_SIZE];
2828
var ret = GetCurrentDirectoryW(STARTING_BUF_SIZE, startingBuffer);
2929
switch (ret)

src/BizHawk.Common/Win32/Win32Imports.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ namespace BizHawk.Common
1414
/// </summary>
1515
public static class Win32Imports
1616
{
17-
public const int MAX_PATH = 260;
17+
public const uint MAX_PATH = 260U;
1818

1919
[Flags]
20-
public enum TPM
20+
public enum TPM : uint
2121
{
2222
LEFTBUTTON = 0x0000,
2323
RIGHTBUTTON = 0x0002,
2424
LEFTALIGN = 0x0000,
25-
CENTERALIGN = 0x000,
26-
RIGHTALIGN = 0x000,
25+
CENTERALIGN = 0x0004,
26+
RIGHTALIGN = 0x0008,
2727
TOPALIGN = 0x0000,
2828
VCENTERALIGN = 0x0010,
2929
BOTTOMALIGN = 0x0020,
3030
HORIZONTAL = 0x0000,
3131
VERTICAL = 0x0040,
3232
NONOTIFY = 0x0080,
3333
RETURNCMD = 0x0100,
34-
RECURSE = 0x0001,
34+
RECURSE = 0x0001, // value missing from official docs, but confirmed by https://github.com/microsoft/windows-rs/blob/bb15076311bf185400ecd244d47596b8415450fa/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs#L3461
3535
HORPOSANIMATION = 0x0400,
3636
HORNEGANIMATION = 0x0800,
3737
VERPOSANIMATION = 0x1000,
3838
VERNEGANIMATION = 0x2000,
3939
NOANIMATION = 0x4000,
40-
LAYOUTRTL = 0x8000,
40+
LAYOUTRTL = 0x8000, // value also missing from official docs, but confirmed by https://github.com/microsoft/windows-rs/blob/bb15076311bf185400ecd244d47596b8415450fa/crates/libs/sys/src/Windows/Win32/UI/WindowsAndMessaging/mod.rs#L3456
4141
}
4242

4343
[DllImport("user32.dll", ExactSpelling = true)]
@@ -53,8 +53,8 @@ public enum TPM
5353
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
5454
public static extern unsafe int FormatMessageW(int flags, IntPtr source, uint messageId, uint languageId, char* outMsg, int size, IntPtr args);
5555

56-
[DllImport("kernel32.dll", ExactSpelling = true)]
57-
public static extern uint GetLastError();
56+
public static uint GetLastError()
57+
=> unchecked((uint) Marshal.GetLastWin32Error());
5858

5959
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
6060
public static extern bool PathRelativePathToW([Out] char[] pszPath, [In] string pszFrom, [In] FileAttributes dwAttrFrom, [In] string pszTo, [In] FileAttributes dwAttrTo);

0 commit comments

Comments
 (0)