Skip to content

Commit 025e9ad

Browse files
control panel: support for ARM64
1 parent 842490a commit 025e9ad

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

AmtPtpControlPanel/Main.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Security.AccessControl;
1616
using System.Reflection;
1717
using Microsoft.Win32;
18+
using System.Diagnostics;
1819

1920
namespace AmtPtpControlPanel
2021
{
@@ -27,10 +28,12 @@ public Main()
2728

2829
private void ctlInstallDriver_Click(object sender, EventArgs e)
2930
{
31+
bool isArm64 = ArchitectureInfo.IsArm64();
32+
3033
string fn = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
31-
@"System32\DriverStore\FileRepository\amtptpdevice.inf_amd64_5de6239780ba286e\AmtPtpDeviceUsbUm.dll");
34+
@"System32\DriverStore\FileRepository\amtptpdevice.inf_" + (isArm64 ? "arm64_fd8449c22cc620c8" : "amd64_5de6239780ba286e") + @"\AmtPtpDeviceUsbUm.dll");
3235
string src = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
33-
@"AmtPtpDeviceUsbUm.dll");
36+
@"AmtPtpDeviceUsbUm" + (isArm64 ? "_ARM64" : "_AMD64") + ".dll");
3437

3538
Action<string> showErr = (string str) =>
3639
{
@@ -453,6 +456,35 @@ public void Dispose()
453456
// Low level stuff
454457
//=================
455458

459+
public class ArchitectureInfo
460+
{
461+
[DllImport("kernel32.dll", EntryPoint = "LoadLibrary")]
462+
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpLibFileName);
463+
[DllImport("kernel32.dll", EntryPoint = "GetProcAddress")]
464+
public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName);
465+
[DllImport("kernel32.dll", EntryPoint = "FreeLibrary")]
466+
public static extern bool FreeLibrary(IntPtr hModule);
467+
468+
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
469+
public delegate bool IsWow64Process2(IntPtr process, out ushort processMachine, out ushort nativeMachine);
470+
471+
public static bool IsArm64()
472+
{
473+
IntPtr lib = LoadLibrary(@"kernel32.dll");
474+
475+
IntPtr pfn = GetProcAddress(lib, "IsWow64Process2");
476+
if (pfn == IntPtr.Zero)
477+
return false;
478+
479+
IsWow64Process2 isWow64Process2 = (IsWow64Process2)Marshal.GetDelegateForFunctionPointer(pfn, typeof(IsWow64Process2));
480+
481+
if (!isWow64Process2(Process.GetCurrentProcess().Handle, out var processMachine, out var nativeMachine))
482+
return false;
483+
484+
return nativeMachine == 0xaa64;
485+
}
486+
}
487+
456488
public class TokenManipulator // https://stackoverflow.com/questions/17031552/how-do-you-take-file-ownership-with-powershell/17047190#17047190
457489
{
458490
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ I'm really happy with the result: the feeling of the MT2 is identical to that of
1616

1717
# Installation
1818

19-
**NOTE**: Only for the MT2 when connected via USB! Bluetooth not supported. ARM64 not supported (at the moment).
19+
**NOTE**: Only for the MT2 when connected via USB, ie bluetooth not supported.
2020

21-
1) Connect the MT2 to the PC via USB and first install the imbushuo driver: download [this file](https://github.com/imbushuo/mac-precision-touchpad/releases/download/2105-3979/Drivers-amd64-ReleaseMSSigned.zip), unzip it, right-click on the INF file and click "Install".
21+
1) Connect the MT2 to the PC via USB and first install the imbushuo driver: download [this file (for x86)](https://github.com/imbushuo/mac-precision-touchpad/releases/download/2105-3979/Drivers-amd64-ReleaseMSSigned.zip) or [this file (for ARM)](https://github.com/imbushuo/mac-precision-touchpad/releases/download/2105-3979/Drivers-arm64-ReleaseMSSigned.zip), unzip it, right-click on the INF file and click "Install".
2222

23-
2) Download the two files of this project from the Releases of this repo (save them in the same directory), start the Control Panel and click on "Install Driver".
23+
2) Download the zip file of this project from the [Releases](https://github.com/vitoplantamura/MagicTrackpad2ForWindows/releases) of this repo, unzip it, start the Control Panel and click on "Install Driver".
2424

2525
# How the Installation Works
2626

0 commit comments

Comments
 (0)