mirror of
https://github.com/soukoku/ntwain.git
synced 2025-07-15 15:03:41 +08:00
Added local 2.5 dsm to samples in case system doesn't have it.
This commit is contained in:
parent
5fa6edab28
commit
513dc96f64
37
samples/WinForm32/DsmLoader.cs
Normal file
37
samples/WinForm32/DsmLoader.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormSample
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// For demoing loading dsm from custom path in case
|
||||||
|
/// it's not installed on system and can't be placed
|
||||||
|
/// besides the exe.
|
||||||
|
/// </summary>
|
||||||
|
static class DsmLoader
|
||||||
|
{
|
||||||
|
static IntPtr __dllPtr;
|
||||||
|
|
||||||
|
public static bool TryUseCustomDSM()
|
||||||
|
{
|
||||||
|
if (__dllPtr == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
var dll = Path.Combine(
|
||||||
|
Path.GetDirectoryName(Environment.ProcessPath ?? Assembly.GetExecutingAssembly().Location)!,
|
||||||
|
"platforms\\TWAINDSM.dll");
|
||||||
|
|
||||||
|
__dllPtr = LoadLibraryW(dll);
|
||||||
|
}
|
||||||
|
return __dllPtr != IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("kernel32", SetLastError = true)]
|
||||||
|
static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,15 @@ namespace WinFormSample
|
|||||||
var libVer = FileVersionInfo.GetVersionInfo(typeof(TwainAppSession).Assembly.Location).FileVersion;
|
var libVer = FileVersionInfo.GetVersionInfo(typeof(TwainAppSession).Assembly.Location).FileVersion;
|
||||||
Text += $"{(TwainPlatform.Is32bit ? " 32bit" : " 64bit")} on NTwain {libVer}";
|
Text += $"{(TwainPlatform.Is32bit ? " 32bit" : " 64bit")} on NTwain {libVer}";
|
||||||
|
|
||||||
|
if (DsmLoader.TryUseCustomDSM())
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Using our own dsm now :)");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Will attempt to use default dsm :(");
|
||||||
|
}
|
||||||
|
|
||||||
TwainPlatform.PreferLegacyDSM = false;
|
TwainPlatform.PreferLegacyDSM = false;
|
||||||
|
|
||||||
twain = new TwainAppSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
|
twain = new TwainAppSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
<None Update="platforms\qwindows.dll">
|
<None Update="platforms\qwindows.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="platforms\TWAINDSM.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
BIN
samples/WinForm32/platforms/TWAINDSM.dll
Normal file
BIN
samples/WinForm32/platforms/TWAINDSM.dll
Normal file
Binary file not shown.
@ -26,5 +26,8 @@
|
|||||||
<None Update="platforms\qwindows.dll">
|
<None Update="platforms\qwindows.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="platforms\TWAINDSM.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
BIN
samples/WinForm64/platforms/TWAINDSM.dll
Normal file
BIN
samples/WinForm64/platforms/TWAINDSM.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user