Added device event.

This commit is contained in:
Eugene Wang
2023-04-01 22:23:44 -04:00
parent 1dd7d811a9
commit d6438c2f54
6 changed files with 70 additions and 10 deletions

View File

@@ -12,19 +12,20 @@ namespace NTwain.Triplets
}
/// <summary>
/// Loads and opens the specified data source.
/// Loads the custom DS data.
/// </summary>
/// <param name="ds"></param>
/// <param name="data"></param>
/// <returns></returns>
public STS Get(ref TW_CUSTOMDSDATA data)
public STS Get(out TW_CUSTOMDSDATA data)
{
data = default;
return DoIt(MSG.GET, ref data);
}
/// <summary>
/// Sets the customs data.
/// Sets the custom DS data.
/// </summary>
/// <param name="ds"></param>
/// <param name="data"></param>
/// <returns></returns>
public STS Set(ref TW_CUSTOMDSDATA data)
{

View File

@@ -0,0 +1,57 @@
using TWAINWorkingGroup;
namespace NTwain.Triplets
{
/// <summary>
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.DEVICEEVENT"/>.
/// </summary>
public class DATDeviceEvent : TripletBase
{
public DATDeviceEvent(TwainSession session) : base(session)
{
}
/// <summary>
/// Gets the device event detail.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public STS Get(out TW_DEVICEEVENT data)
{
data = default;
return DoIt(MSG.GET, ref data);
}
STS DoIt(MSG msg, ref TW_DEVICEEVENT data)
{
var rc = STS.FAILURE;
if (TwainPlatform.IsWindows)
{
var app = Session.AppIdentity;
var ds = Session.CurrentSource;
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
{
rc = (STS)NativeMethods.WindowsTwain32DsmEntryDeviceevent(ref app, ref ds, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
}
else
{
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryDeviceevent(ref app, ref ds, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
}
}
else if (TwainPlatform.IsMacOSX)
{
TW_IDENTITY_MACOSX app = Session.AppIdentity;
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
if (TwainPlatform.PreferLegacyDSM)
{
rc = (STS)NativeMethods.MacosxTwainDsmEntryDeviceevent(ref app, ref ds, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
}
else
{
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryDeviceevent(ref app, ref ds, DG.CONTROL, DAT.DEVICEEVENT, msg, ref data);
}
}
return rc;
}
}
}

View File

@@ -18,8 +18,9 @@ namespace NTwain.Triplets
/// </summary>
/// <param name="entry"></param>
/// <returns></returns>
public STS Get(ref TW_ENTRYPOINT_DELEGATES entry)
public STS Get(out TW_ENTRYPOINT_DELEGATES entry)
{
entry = default;
TW_ENTRYPOINT rawentry = default;
var rc = DoIt(MSG.GET, ref rawentry);
if (rc == STS.SUCCESS)

View File

@@ -34,8 +34,7 @@ namespace NTwain.Triplets
// determine memory mgmt routines used
if ((((DG)Session.AppIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
{
TW_ENTRYPOINT_DELEGATES entry = default;
if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
if (Session.DGControl.EntryPoint.Get(out TW_ENTRYPOINT_DELEGATES entry) == STS.SUCCESS)
{
Session._entryPoint = entry;
}

View File

@@ -27,5 +27,8 @@
private DATCustomDsData? _customDsData;
public DATCustomDsData CustomDsData => _customDsData ??= new DATCustomDsData(Session);
private DATDeviceEvent? _deviceEvent;
public DATDeviceEvent DeviceEvent => _deviceEvent ??= new DATDeviceEvent(Session);
}
}

View File

@@ -77,8 +77,7 @@ namespace NTwain
{
get
{
TW_CUSTOMDSDATA data = default;
var sts = DGControl.CustomDsData.Get(ref data);
var sts = DGControl.CustomDsData.Get(out TW_CUSTOMDSDATA data);
if (sts == STS.SUCCESS)
{
if (data.hData != IntPtr.Zero && data.InfoLength > 0)