mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Added custom ds data and fixed copy paste errors.
This commit is contained in:
66
src/NTwain/Triplets/DATCustomDsData.cs
Normal file
66
src/NTwain/Triplets/DATCustomDsData.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using TWAINWorkingGroup;
|
||||
|
||||
namespace NTwain.Triplets
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains calls used with <see cref="DG.CONTROL"/> and <see cref="DAT.CUSTOMDSDATA"/>.
|
||||
/// </summary>
|
||||
public class DATCustomDsData : TripletBase
|
||||
{
|
||||
public DATCustomDsData(TwainSession session) : base(session)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and opens the specified data source.
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS Get(ref TW_CUSTOMDSDATA data)
|
||||
{
|
||||
return DoIt(MSG.GET, ref data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the customs data.
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS Set(ref TW_CUSTOMDSDATA data)
|
||||
{
|
||||
return DoIt(MSG.SET, ref data);
|
||||
}
|
||||
|
||||
STS DoIt(MSG msg, ref TW_CUSTOMDSDATA data)
|
||||
{
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session.AppIdentity;
|
||||
var ds = Session.CurrentSource;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryCustomdsdata(ref app, ref ds, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryCustomdsdata(ref app, ref ds, DG.CONTROL, DAT.CUSTOMDSDATA, 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.MacosxTwainDsmEntryCustomdsdata(ref app, ref ds, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryCustomdsdata(ref app, ref ds, DG.CONTROL, DAT.CUSTOMDSDATA, msg, ref data);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,11 +55,11 @@ namespace NTwain.Triplets
|
||||
TW_IDENTITY_LEGACY dummy = default;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.PARENT, msg, ref entry);
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.PARENT, msg, ref entry);
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
}
|
||||
}
|
||||
//else if (TwainPlatform.IsLinux)
|
||||
@@ -72,11 +72,11 @@ namespace NTwain.Triplets
|
||||
TW_IDENTITY_MACOSX dummy = default;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.PARENT, msg, ref entry);
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.PARENT, msg, ref entry);
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryEntrypoint(ref app, ref dummy, DG.CONTROL, DAT.ENTRYPOINT, msg, ref entry);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace NTwain.Triplets
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
@@ -38,11 +38,11 @@ namespace NTwain.Triplets
|
||||
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryStatusState3(ref app, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
@@ -63,11 +63,11 @@ namespace NTwain.Triplets
|
||||
var app = Session.AppIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryStatus(ref app, ref ds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryStatus(ref app, ref ds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryStatus(ref app, ref ds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryStatus(ref app, ref ds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
@@ -76,11 +76,11 @@ namespace NTwain.Triplets
|
||||
TW_IDENTITY_MACOSX osxds = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryStatus(ref app, ref osxds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryStatus(ref app, ref osxds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryStatus(ref app, ref osxds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref status);
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryStatus(ref app, ref osxds, DG.CONTROL, DAT.STATUS, MSG.GET, ref status);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -33,11 +33,11 @@ namespace NTwain.Triplets
|
||||
var ds = Session.CurrentSource;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref extendedStatus);
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref extendedStatus);
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
@@ -46,11 +46,11 @@ namespace NTwain.Triplets
|
||||
TW_IDENTITY_MACOSX ds = Session.CurrentSource;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref extendedStatus);
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.IDENTITY, MSG.GET, ref extendedStatus);
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryStatusutf8(ref app, ref ds, DG.CONTROL, DAT.STATUSUTF8, MSG.GET, ref extendedStatus);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -24,5 +24,8 @@
|
||||
private DATStatusUtf8? _statusUtf8;
|
||||
public DATStatusUtf8 StatusUtf8 => _statusUtf8 ??= new DATStatusUtf8(Session);
|
||||
|
||||
private DATCustomDsData? _customDsData;
|
||||
public DATCustomDsData CustomDsData => _customDsData ??= new DATCustomDsData(Session);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using NTwain.Triplets;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TWAINWorkingGroup;
|
||||
|
||||
namespace NTwain
|
||||
@@ -68,6 +69,59 @@ namespace NTwain
|
||||
STATE _state = STATE.S1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the current source's settings as opaque data.
|
||||
/// Returns null if not supported. This is only valid in <see cref="STATE.S4"/>.
|
||||
/// </summary>
|
||||
public byte[]? CustomDsData
|
||||
{
|
||||
get
|
||||
{
|
||||
TW_CUSTOMDSDATA data = default;
|
||||
var sts = DGControl.CustomDsData.Get(ref data);
|
||||
if (sts == STS.SUCCESS)
|
||||
{
|
||||
if (data.hData != IntPtr.Zero && data.InfoLength > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lockedPtr = Lock(data.hData);
|
||||
var bytes = new byte[data.InfoLength];
|
||||
Marshal.Copy(lockedPtr, bytes, 0, bytes.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Unlock(data.hData);
|
||||
Free(data.hData);
|
||||
}
|
||||
}
|
||||
//return Array.Empty<byte>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null || value.Length == 0) return;
|
||||
|
||||
TW_CUSTOMDSDATA data = default;
|
||||
data.InfoLength = (uint)value.Length;
|
||||
data.hData = Alloc(data.InfoLength);
|
||||
try
|
||||
{
|
||||
var lockedPtr = Lock(data.hData);
|
||||
Marshal.Copy(value, 0, lockedPtr, value.Length);
|
||||
Unlock(data.hData);
|
||||
var sts = DGControl.CustomDsData.Set(ref data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// should be freed already if no error but just in case
|
||||
if (data.hData != IntPtr.Zero) Free(data.hData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// TWAIN triplet API calls with <see cref="DG.CONTROL"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user