2023-04-01 19:26:59 +08:00
|
|
|
|
using NTwain;
|
2023-04-02 00:57:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2023-04-01 19:26:59 +08:00
|
|
|
|
using System.Reflection;
|
2023-04-02 00:57:07 +08:00
|
|
|
|
using TWAINWorkingGroup;
|
2023-04-01 19:26:59 +08:00
|
|
|
|
|
|
|
|
|
namespace SampleConsole
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2023-04-02 00:57:07 +08:00
|
|
|
|
TwainPlatform.PreferLegacyDSM = true;
|
|
|
|
|
|
|
|
|
|
var twain = new TwainSession(Assembly.GetExecutingAssembly().Location);
|
2023-04-01 20:01:20 +08:00
|
|
|
|
twain.StateChanged += Twain_StateChanged;
|
2023-04-02 00:57:07 +08:00
|
|
|
|
|
|
|
|
|
var hwnd = IntPtr.Zero;
|
|
|
|
|
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
|
|
|
|
Debug.WriteLine($"OpenDSM={rc}");
|
|
|
|
|
|
|
|
|
|
if (rc == TWAINWorkingGroup.STS.SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine($"CloseDSM={rc}");
|
|
|
|
|
rc = twain.DGControl.Parent.CloseDSM(ref hwnd);
|
|
|
|
|
}
|
2023-04-01 20:01:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Twain_StateChanged(TwainSession session, TWAINWorkingGroup.STATE state)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"State changed to {state}");
|
2023-04-01 19:26:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|