Skip to content

Commit 28c34ac

Browse files
committed
Replace many external declarations w/ CsWin32
1 parent 083e912 commit 28c34ac

24 files changed

+229
-111
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="8.0.4" />
1919
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
2020
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
21+
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.183" />
2122
<PackageVersion Include="MSTest" Version="3.8.3" />
2223
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
2324
<PackageVersion Include="Nullable" Version="1.3.1" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
</PropertyGroup>
5+
<Import Project="../MainSlnCommon.props" />
6+
<ItemGroup>
7+
</ItemGroup>
8+
</Project>

src/BizHawk.Bizware.Input/KeyMouseInput/RawKeyMouseInput.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using BizHawk.Common;
88
using BizHawk.Common.CollectionExtensions;
99

10+
using Windows.Win32;
11+
1012
using static BizHawk.Common.RawInputImports;
1113
using static BizHawk.Common.WmImports;
1214

src/BizHawk.Client.DiscoHawk/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using BizHawk.Common.StringExtensions;
99
using BizHawk.Emulation.DiscSystem;
1010

11+
using Windows.Win32;
12+
1113
namespace BizHawk.Client.DiscoHawk
1214
{
1315
internal static class Program
@@ -83,22 +85,22 @@ private static void Main(string[] args)
8385

8486
if (dllDir.ContainsOrdinal(';'))
8587
{
86-
var dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir, null, 0);
88+
var dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir);
8789
if (dllShortPathLen == 0)
8890
{
8991
MessageBox.Show(SEMICOLON_IN_DIR_MSG);
9092
return;
9193
}
9294

9395
var dllShortPathBuffer = new char[dllShortPathLen];
94-
dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir, dllShortPathBuffer, dllShortPathLen);
96+
dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir, dllShortPathBuffer);
9597
if (dllShortPathLen == 0)
9698
{
9799
MessageBox.Show(SEMICOLON_IN_DIR_MSG);
98100
return;
99101
}
100102

101-
dllDir = new string(dllShortPathBuffer, 0, dllShortPathLen);
103+
dllDir = dllShortPathBuffer.AsSpan(start: 0, length: (int) dllShortPathLen).ToString();
102104
if (dllDir.ContainsOrdinal(';'))
103105
{
104106
MessageBox.Show(SEMICOLON_IN_DIR_MSG);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
using BizHawk.Common;
77

8+
using Windows.Win32;
9+
810
using static BizHawk.Common.Shell32Imports;
911

1012
namespace BizHawk.Client.EmuHawk

src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using BizHawk.Common;
55
using BizHawk.Common.StringExtensions;
66

7+
using Windows.Win32;
8+
79
namespace BizHawk.Client.EmuHawk
810
{
911
public static class EmuHawkUtil

src/BizHawk.Client.EmuHawk/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using BizHawk.Client.EmuHawk.CustomControls;
1515
using BizHawk.Emulation.Cores;
1616

17+
using Windows.Win32;
18+
1719
namespace BizHawk.Client.EmuHawk
1820
{
1921
internal static class Program
@@ -132,22 +134,22 @@ private static int SubMain(string[] args)
132134

133135
if (dllDir.ContainsOrdinal(';'))
134136
{
135-
var dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir, null, 0);
137+
var dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir);
136138
if (dllShortPathLen == 0)
137139
{
138140
MessageBox.Show(SEMICOLON_IN_DIR_MSG);
139141
return -1;
140142
}
141143

142144
var dllShortPathBuffer = new char[dllShortPathLen];
143-
dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir, dllShortPathBuffer, dllShortPathLen);
145+
dllShortPathLen = Win32Imports.GetShortPathNameW(dllDir, dllShortPathBuffer);
144146
if (dllShortPathLen == 0)
145147
{
146148
MessageBox.Show(SEMICOLON_IN_DIR_MSG);
147149
return -1;
148150
}
149151

150-
dllDir = new string(dllShortPathBuffer, 0, dllShortPathLen);
152+
dllDir = dllShortPathBuffer.AsSpan(start: 0, length: (int) dllShortPathLen).ToString();
151153
if (dllDir.ContainsOrdinal(';'))
152154
{
153155
MessageBox.Show(SEMICOLON_IN_DIR_MSG);

src/BizHawk.Client.EmuHawk/ScreenSaver.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using BizHawk.Common;
22

3+
using Windows.Win32;
4+
using Windows.Win32.UI.WindowsAndMessaging;
5+
36
namespace BizHawk.Client.EmuHawk
47
{
58
/// <remarks>Derived from http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx</remarks>
@@ -19,17 +22,18 @@ public int Duration
1922
{
2023
get
2124
{
22-
const int SPI_GETSCREENSAVERTIMEOUT = 14;
23-
int value = default;
24-
Win32Imports.SystemParametersInfoW(SPI_GETSCREENSAVERTIMEOUT, 0, ref value, 0);
25-
return value;
25+
_ = Win32Imports.SystemParametersInfoW(
26+
SYSTEM_PARAMETERS_INFO_ACTION.SPI_GETSCREENSAVETIMEOUT,
27+
uiParam: 0,
28+
out var value);
29+
return unchecked((int) value);
2630
}
2731
set
2832
{
29-
const int SPI_SETSCREENSAVERTIMEOUT = 15;
30-
const int SPIF_SENDWININICHANGE = 2;
31-
int nullVar = default;
32-
Win32Imports.SystemParametersInfoW(SPI_SETSCREENSAVERTIMEOUT, value, ref nullVar, SPIF_SENDWININICHANGE);
33+
_ = Win32Imports.SystemParametersInfoW(
34+
SYSTEM_PARAMETERS_INFO_ACTION.SPI_SETSCREENSAVETIMEOUT,
35+
unchecked((uint) value),
36+
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS.SPIF_SENDWININICHANGE);
3337
}
3438
}
3539
}

src/BizHawk.Client.EmuHawk/Throttle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using BizHawk.Client.Common;
55
using BizHawk.Common;
66

7+
using Windows.Win32;
8+
79
//this throttle is nitsuja's fine-tuned techniques from desmume
810

911
namespace BizHawk.Client.EmuHawk

src/BizHawk.Common/BizHawk.Common.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
<PackageReference Include="CommunityToolkit.HighPerformance" />
1212
<PackageReference Include="Microsoft.Bcl.HashCode" />
1313
<PackageReference Include="Microsoft.Win32.Registry" />
14+
<PackageReference Include="Microsoft.Windows.CsWin32" />
1415
<PackageReference Include="PolySharp" />
1516
<PackageReference Include="System.ComponentModel.Annotations" />
1617
<PackageReference Include="System.Memory" />
1718
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
18-
</ItemGroup>
19-
<ItemGroup>
2019
<Analyzer Include="$(MSBuildProjectDirectory)/../../References/BizHawk.SrcGen.VersionInfo.dll" />
2120
</ItemGroup>
2221
<Target Name="InstallGitHooks" AfterTargets="PreBuildEvent">

0 commit comments

Comments
 (0)