mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-20 02:37:57 +08:00
Progress with OpenDS.
This commit is contained in:
@@ -24,7 +24,7 @@ namespace WinForm32
|
|||||||
|
|
||||||
private static void Twain_StateChanged(TwainSession session, STATE state)
|
private static void Twain_StateChanged(TwainSession session, STATE state)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"State changed to {state}");
|
Debug.WriteLine($"State changed to {state}");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHandleCreated(EventArgs e)
|
protected override void OnHandleCreated(EventArgs e)
|
||||||
@@ -35,6 +35,7 @@ namespace WinForm32
|
|||||||
var hwnd = this.Handle;
|
var hwnd = this.Handle;
|
||||||
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
||||||
Debug.WriteLine($"OpenDSM={rc}");
|
Debug.WriteLine($"OpenDSM={rc}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosing(CancelEventArgs e)
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
|
96
src/NTwain/Triplets/DATIdentity.cs
Normal file
96
src/NTwain/Triplets/DATIdentity.cs
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using TWAINWorkingGroup;
|
||||||
|
|
||||||
|
namespace NTwain.Triplets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.IDENTITY"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class DATIdentity : TripletBase
|
||||||
|
{
|
||||||
|
public DATIdentity(TwainSession session) : base(session)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads and opens the specified DS.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public STS OpenDS(ref TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
STS rc;
|
||||||
|
if ((rc = DoIt(MSG.OPENDS, ref ds, true)) == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Session.State = STATE.S4;
|
||||||
|
//// determine memory mgmt routines used
|
||||||
|
//if ((((DG)Session._appIdentityLegacy.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||||
|
//{
|
||||||
|
// TW_ENTRYPOINT_DELEGATES entry = default;
|
||||||
|
// if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
||||||
|
// {
|
||||||
|
// Session._entryPoint = entry;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// Closes the currently open DS.
|
||||||
|
///// </summary>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public STS CloseDS(ref IntPtr hwnd)
|
||||||
|
//{
|
||||||
|
// STS rc;
|
||||||
|
// if ((rc = DoIt(MSG.CLOSEDSM, ref hwnd)) == STS.SUCCESS)
|
||||||
|
// {
|
||||||
|
// Session._hwnd = IntPtr.Zero;
|
||||||
|
// Session._entryPoint = default;
|
||||||
|
// Session.State = STATE.S2;
|
||||||
|
// }
|
||||||
|
// return rc;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
STS DoIt(MSG msg, ref TW_IDENTITY_LEGACY ds, bool updateSource)
|
||||||
|
{
|
||||||
|
var rc = STS.FAILURE;
|
||||||
|
if (TwainPlatform.IsWindows)
|
||||||
|
{
|
||||||
|
var app = Session._appIdentityLegacy;
|
||||||
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
|
{
|
||||||
|
rc = (STS)NativeMethods.WindowsTwain32DsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||||
|
}
|
||||||
|
if (updateSource && rc == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Session._dsIdentityLegacy = ds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (TwainPlatform.IsMacOSX)
|
||||||
|
{
|
||||||
|
var app = Session._appIdentityOSX;
|
||||||
|
TW_IDENTITY_MACOSX osxds = ds;
|
||||||
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
|
{
|
||||||
|
rc = (STS)NativeMethods.MacosxTwainDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||||
|
}
|
||||||
|
if (updateSource && rc == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Session._dsIdentityOSX = osxds;
|
||||||
|
Session._dsIdentityLegacy = osxds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -15,5 +15,8 @@
|
|||||||
private DATEntryPoint? _entryPoint;
|
private DATEntryPoint? _entryPoint;
|
||||||
public DATEntryPoint EntryPoint => _entryPoint ??= new DATEntryPoint(Session);
|
public DATEntryPoint EntryPoint => _entryPoint ??= new DATEntryPoint(Session);
|
||||||
|
|
||||||
|
private DATIdentity? _identity;
|
||||||
|
public DATIdentity Identity => _identity ??= new DATIdentity(Session);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user