Replaced preproc guards that no longer work.

This commit is contained in:
Eugene Wang
2026-01-01 22:33:40 -05:00
parent 4de4bac806
commit d31c7a2f9f
2 changed files with 26 additions and 9 deletions

View File

@@ -0,0 +1,16 @@
#if NETFRAMEWORK
using System;
namespace NTwain;
/// <summary>
/// Hack to make it build without preprocessor directives all over.
/// </summary>
static class OperatingSystem
{
public static bool IsWindows()
{
return Environment.OSVersion.Platform == PlatformID.Win32NT;
}
}
#endif

View File

@@ -30,9 +30,10 @@ namespace NTwain
{
if (logger != null) _logger = logger;
#if WINDOWS || NETFRAMEWORK
DSM.DsmLoader.TryLoadCustomDSM(Logger);
#endif
if (OperatingSystem.IsWindows())
DSM.DsmLoader.TryLoadCustomDSM(Logger);
_appIdentity = appId;
_legacyCallbackDelegate = LegacyCallbackHandler;
@@ -69,9 +70,8 @@ namespace NTwain
{
IsBackground = true
};
#if WINDOWS || NETFRAMEWORK
t.SetApartmentState(ApartmentState.STA); // just in case
#endif
if (OperatingSystem.IsWindows())
t.SetApartmentState(ApartmentState.STA); // just in case
t.Start();
}
@@ -102,9 +102,10 @@ namespace NTwain
_xferReady.Dispose();
//_bgPendingMsgs.CompleteAdding();
}
#if WINDOWS || NETFRAMEWORK
if (_procEvent.pEvent != IntPtr.Zero) Marshal.FreeHGlobal(_procEvent.pEvent);
#endif
if (OperatingSystem.IsWindows())
if (_procEvent.pEvent != IntPtr.Zero) Marshal.FreeHGlobal(_procEvent.pEvent);
disposedValue = true;
}
}