From 7da4a4056c500eb275fc65f5bd88ca4c4df02cf3 Mon Sep 17 00:00:00 2001 From: maniglia Date: Fri, 27 Dec 2024 11:28:07 +0100 Subject: [PATCH] Testing --- .../CubeProgrammerApi.cs | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs b/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs index 45e73e3..15768f8 100644 --- a/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs +++ b/src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs @@ -75,7 +75,7 @@ private void LoadStLinkDriver() out IntPtr handle)) { var error = Marshal.GetLastWin32Error(); - this._logger?.LogError("Loading with NativeLibrary {0} {1} library error: {3} !", target + @"\STLinkUSBDriver.dll", Environment.Is64BitProcess ? "x64" : "x86", error); + this._logger?.LogError("Loading with NativeLibrary {0} {1} library error: {2} !", target + @"\STLinkUSBDriver.dll", Environment.Is64BitProcess ? "x64" : "x86", error); this._handleSTLinkDriver = null; } else @@ -107,7 +107,7 @@ private void LoadStLinkDriver() if (this._handleSTLinkDriver.IsInvalid) { int error = Marshal.GetLastWin32Error(); - this._logger?.LogError("Loading {0} {1} library error: {3} !", target + @"\STLinkUSBDriver.dll", Environment.Is64BitProcess ? "x64" : "x86", error); + this._logger?.LogError("Loading {0} {1} library error: {2} !", target + @"\STLinkUSBDriver.dll", Environment.Is64BitProcess ? "x64" : "x86", error); this._handleSTLinkDriver = null; } else @@ -139,7 +139,7 @@ private void LoadProgrammer() out IntPtr handle)) { var error = Marshal.GetLastWin32Error(); - this._logger?.LogError("Loading with NativeLibrary {0} {1} library error: {3} !", target, Environment.Is64BitProcess ? "x64" : "x86", error); + this._logger?.LogError("Loading with NativeLibrary {0} {1} library error: {2} !", target, Environment.Is64BitProcess ? "x64" : "x86", error); this._handleProgrammer = null; } else @@ -167,24 +167,27 @@ private void LoadProgrammer() var result = Native.Utility.SetDllDirectoryW(target); - if (!result) + if (result) + { + this._handleProgrammer = Native.Utility.LoadLibraryEx(target + @"\Programmer.dll", IntPtr.Zero, dwFlags); + + if (this._handleProgrammer.IsInvalid) + { + int error = Marshal.GetLastWin32Error(); + this._logger?.LogError("Loading {0} {1} library error: {2} !", target + @"\Programmer.dll", Environment.Is64BitProcess ? "x64" : "x86", error); + this._handleProgrammer = null; + } + else + { + this._logger?.LogInformation("Loading {0} - {1} library.", "Programmer.dll", Environment.Is64BitProcess ? "x64" : "x86"); + } + } + else { int error = Marshal.GetLastWin32Error(); + this._logger?.LogError("SetDllDirectory {0} error: {1} !", target, error); } - } - - this._handleProgrammer = Native.Utility.LoadLibraryEx(target + @"\Programmer.dll", IntPtr.Zero, dwFlags); - - if (this._handleProgrammer.IsInvalid) - { - int error = Marshal.GetLastWin32Error(); - this._logger?.LogError("Loading {0} {1} library error: {3} !", target + @"\Programmer.dll", Environment.Is64BitProcess ? "x64" : "x86", error); - this._handleProgrammer = null; - } - else - { - this._logger?.LogInformation("Loading {0} - {1} library.", "Programmer.dll", Environment.Is64BitProcess ? "x64" : "x86"); - } + } #endif } }