Files
ntwain/samples/WinForm32/DsmLoader.cs
Eugene Wang fe89e661fc V4 add extimginfo (#37)
* Added my old struct size tester cpp proj.
* Added transfercanceled event like PR #35.
* Renamed datatransferred event.
* Idea for getting EXT_IMAGEINFO in transferred event.
* Renamed twain const and platform classes to shorter name.
* First attempt at reading TW_INFO, probably not correct.
2023-04-09 17:52:23 -04:00

39 lines
1.0 KiB
C#

using NTwain.Data;
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 don't want to 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)!,
$@"runtimes\win-{(TWPlatform.Is32bit ? "x86" : "x64")}\native\TWAINDSM.dll");
__dllPtr = LoadLibraryW(dll);
}
return __dllPtr != IntPtr.Zero;
}
[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
}
}