diff --git a/samples/WinForm32/DsmLoader.cs b/samples/WinForm32/DsmLoader.cs
new file mode 100644
index 0000000..ccb7c4e
--- /dev/null
+++ b/samples/WinForm32/DsmLoader.cs
@@ -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
+{
+ ///
+ /// For demoing loading dsm from custom path in case
+ /// it's not installed on system and can't be placed
+ /// besides the exe.
+ ///
+ 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);
+ }
+}
diff --git a/samples/WinForm32/Form1.cs b/samples/WinForm32/Form1.cs
index 9a250c0..60136c1 100644
--- a/samples/WinForm32/Form1.cs
+++ b/samples/WinForm32/Form1.cs
@@ -17,7 +17,16 @@ namespace WinFormSample
InitializeComponent();
var libVer = FileVersionInfo.GetVersionInfo(typeof(TwainAppSession).Assembly.Location).FileVersion;
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;
twain = new TwainAppSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
diff --git a/samples/WinForm32/WinForm32.csproj b/samples/WinForm32/WinForm32.csproj
index afa7141..f303a7d 100644
--- a/samples/WinForm32/WinForm32.csproj
+++ b/samples/WinForm32/WinForm32.csproj
@@ -17,6 +17,9 @@
PreserveNewest
+
+ PreserveNewest
+
\ No newline at end of file
diff --git a/samples/WinForm32/platforms/TWAINDSM.dll b/samples/WinForm32/platforms/TWAINDSM.dll
new file mode 100644
index 0000000..7f38f2f
Binary files /dev/null and b/samples/WinForm32/platforms/TWAINDSM.dll differ
diff --git a/samples/WinForm64/WinForm64.csproj b/samples/WinForm64/WinForm64.csproj
index 43e55e9..0477bfa 100644
--- a/samples/WinForm64/WinForm64.csproj
+++ b/samples/WinForm64/WinForm64.csproj
@@ -26,5 +26,8 @@
PreserveNewest
+
+ PreserveNewest
+
\ No newline at end of file
diff --git a/samples/WinForm64/platforms/TWAINDSM.dll b/samples/WinForm64/platforms/TWAINDSM.dll
new file mode 100644
index 0000000..2b981aa
Binary files /dev/null and b/samples/WinForm64/platforms/TWAINDSM.dll differ