mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-29 03:32:01 +08:00
38 lines
953 B
C#
38 lines
953 B
C#
![]() |
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);
|
|||
|
}
|
|||
|
}
|