Skip to content

Commit

Permalink
Merge pull request #177 from K-Society/experimental
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
maniglia authored Dec 27, 2024
2 parents 37041aa + 64ca1a1 commit d12c20a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/01/KSociety.SharpCubeProgrammer/CubeProgrammerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void LoadStLinkDriver()
hasKB2533623 = Native.Utility.GetProcAddress(hModule, "AddDllDirectory") != IntPtr.Zero;
}

int dwFlags = 0;
var dwFlags = 0;

if (hasKB2533623)
{
Expand All @@ -106,7 +106,7 @@ private void LoadStLinkDriver()

if (this._handleSTLinkDriver.IsInvalid)
{
int error = Marshal.GetLastWin32Error();
var error = Marshal.GetLastWin32Error();
this._logger?.LogError("Loading {0} {1} library error: {2} !", target + @"\STLinkUSBDriver.dll", Environment.Is64BitProcess ? "x64" : "x86", error);
this._handleSTLinkDriver = null;
}
Expand Down Expand Up @@ -158,35 +158,35 @@ private void LoadProgrammer()
hasKB2533623 = Native.Utility.GetProcAddress(hModule, "SetDllDirectoryW") != IntPtr.Zero;
}

int dwFlags = 0;
var dwFlags = 0;

if (hasKB2533623)
{
// If KB2533623 is installed then specify the more secure LOAD_LIBRARY_SEARCH_USER_DIRS in dwFlags
//dwFlags = Native.Utility.LOAD_LIBRARY_SEARCH_USER_DIRS;
// If KB2533623 is installed then specify the more secure LOAD_WITH_ALTERED_SEARCH_PATH in dwFlags
dwFlags = Native.Utility.LOAD_WITH_ALTERED_SEARCH_PATH;

var result = Native.Utility.SetDllDirectoryW(target);
//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();
var 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);
}
//}
//else
//{
// var error = Marshal.GetLastWin32Error();
// this._logger?.LogError("SetDllDirectory {0} error: {1} !", target, error);
//}
}
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions src/01/KSociety.SharpCubeProgrammer/Native/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace SharpCubeProgrammer.Native
/// </summary>
internal static class Utility
{
internal const int LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008;

/// <summary>
/// This value represents the recommended maximum number of directories an application should include in its DLL search path.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.csproj.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>

<AssemblyOriginatorKeyFile>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)ksociety.snk))</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down

0 comments on commit d12c20a

Please sign in to comment.