mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-18 09:44:24 +08:00
Added GetMetrics() wrapper.
This commit is contained in:
@@ -26,6 +26,29 @@ namespace TWAINWorkingGroup
|
|||||||
True = 1
|
True = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A more dotnet-friendly representation of <see cref="TW_METRICS"/>.
|
||||||
|
/// </summary>
|
||||||
|
public struct Metrics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Return code of querying the metrics.
|
||||||
|
/// </summary>
|
||||||
|
public STS ReturnCode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of sheets of paper processed by the scanner.
|
||||||
|
/// </summary>
|
||||||
|
public int Sheets;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of images made available for transfer by the driver. This is not
|
||||||
|
/// necessarily the same as the number of images actually transferred, since the
|
||||||
|
/// application may opt to skip transfers or to end without transferring all images.
|
||||||
|
/// </summary>
|
||||||
|
public int Images;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A more dotnet-friendly representation of <see cref="TW_ENUMERATION"/>.
|
/// A more dotnet-friendly representation of <see cref="TW_ENUMERATION"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1121,11 +1121,11 @@ namespace TWAINWorkingGroup
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to register callbacks.
|
/// Used to register callbacks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable")]
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
public partial struct TW_CALLBACK
|
public partial struct TW_CALLBACK
|
||||||
{
|
{
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr CallBackProc;
|
public IntPtr CallBackProc;
|
||||||
public uint RefCon;
|
public uint RefCon;
|
||||||
public ushort Message;
|
public ushort Message;
|
||||||
@@ -1137,9 +1137,9 @@ namespace TWAINWorkingGroup
|
|||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
public partial struct TW_CALLBACK2
|
public partial struct TW_CALLBACK2
|
||||||
{
|
{
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr CallBackProc;
|
public IntPtr CallBackProc;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public UIntPtr RefCon;
|
public UIntPtr RefCon;
|
||||||
public ushort Message;
|
public ushort Message;
|
||||||
}
|
}
|
||||||
@@ -1152,7 +1152,7 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public CAP Cap;
|
public CAP Cap;
|
||||||
public TWON ConType;
|
public TWON ConType;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr hContainer;
|
public IntPtr hContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1193,7 +1193,7 @@ namespace TWAINWorkingGroup
|
|||||||
public partial struct TW_CUSTOMDSDATA
|
public partial struct TW_CUSTOMDSDATA
|
||||||
{
|
{
|
||||||
public uint InfoLength;
|
public uint InfoLength;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr hData;
|
public IntPtr hData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1235,36 +1235,36 @@ namespace TWAINWorkingGroup
|
|||||||
public partial struct TW_ENTRYPOINT
|
public partial struct TW_ENTRYPOINT
|
||||||
{
|
{
|
||||||
public UInt32 Size;
|
public UInt32 Size;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_Entry;
|
public IntPtr DSM_Entry;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemAllocate;
|
public IntPtr DSM_MemAllocate;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemFree;
|
public IntPtr DSM_MemFree;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemLock;
|
public IntPtr DSM_MemLock;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemUnlock;
|
public IntPtr DSM_MemUnlock;
|
||||||
}
|
}
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
public partial struct TW_ENTRYPOINT_LINUX64
|
public partial struct TW_ENTRYPOINT_LINUX64
|
||||||
{
|
{
|
||||||
public long Size;
|
public long Size;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_Entry;
|
public IntPtr DSM_Entry;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemAllocate;
|
public IntPtr DSM_MemAllocate;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemFree;
|
public IntPtr DSM_MemFree;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemLock;
|
public IntPtr DSM_MemLock;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_MemUnlock;
|
public IntPtr DSM_MemUnlock;
|
||||||
}
|
}
|
||||||
public partial struct TW_ENTRYPOINT_DELEGATES
|
public partial struct TW_ENTRYPOINT_DELEGATES
|
||||||
{
|
{
|
||||||
public UInt32 Size;
|
public UInt32 Size;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr DSM_Entry;
|
public IntPtr DSM_Entry;
|
||||||
public DSM_MEMALLOC DSM_MemAllocate;
|
public DSM_MEMALLOC DSM_MemAllocate;
|
||||||
public DSM_MEMFREE DSM_MemFree;
|
public DSM_MEMFREE DSM_MemFree;
|
||||||
@@ -1312,11 +1312,11 @@ namespace TWAINWorkingGroup
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to pass application events/messages from the application to the Source.
|
/// Used to pass application events/messages from the application to the Source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable")]
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
public partial struct TW_EVENT
|
public partial struct TW_EVENT
|
||||||
{
|
{
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr pEvent;
|
public IntPtr pEvent;
|
||||||
public ushort TWMessage;
|
public ushort TWMessage;
|
||||||
}
|
}
|
||||||
@@ -1347,7 +1347,7 @@ namespace TWAINWorkingGroup
|
|||||||
public UInt32 DescriptorCount;
|
public UInt32 DescriptorCount;
|
||||||
public UInt32 MaxDescriptorCount;
|
public UInt32 MaxDescriptorCount;
|
||||||
public UInt32 Condition;
|
public UInt32 Condition;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr hDescriptors;
|
public IntPtr hDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1361,7 +1361,7 @@ namespace TWAINWorkingGroup
|
|||||||
public ushort ItemType;
|
public ushort ItemType;
|
||||||
public ushort NumItems;
|
public ushort NumItems;
|
||||||
public ushort ReturnCode;
|
public ushort ReturnCode;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public UIntPtr Item;
|
public UIntPtr Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1994,8 +1994,8 @@ namespace TWAINWorkingGroup
|
|||||||
/// Provides information about the currently selected device.
|
/// Provides information about the currently selected device.
|
||||||
/// TBD -- need a 32/64 bit solution for this mess
|
/// TBD -- need a 32/64 bit solution for this mess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SuppressMessage("Microsoft.Portability", "CA1900:ValueTypeFieldsShouldBePortable", MessageId = "ModifiedTimeDate")]
|
|
||||||
[SuppressMessage("Microsoft.Portability", "CA1900:ValueTypeFieldsShouldBePortable", MessageId = "CreateTimeDate")]
|
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 2)]
|
[StructLayout(LayoutKind.Explicit, Pack = 2)]
|
||||||
public partial struct TW_FILESYSTEM
|
public partial struct TW_FILESYSTEM
|
||||||
{
|
{
|
||||||
@@ -2005,7 +2005,7 @@ namespace TWAINWorkingGroup
|
|||||||
[FieldOffset(256)]
|
[FieldOffset(256)]
|
||||||
public TW_STR255 OutputName;
|
public TW_STR255 OutputName;
|
||||||
|
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
[FieldOffset(512)]
|
[FieldOffset(512)]
|
||||||
public IntPtr Context;
|
public IntPtr Context;
|
||||||
|
|
||||||
@@ -2049,7 +2049,7 @@ namespace TWAINWorkingGroup
|
|||||||
[FieldOffset(1127)] // 620 + 508 - 1
|
[FieldOffset(1127)] // 620 + 508 - 1
|
||||||
private byte ReservedEnd;
|
private byte ReservedEnd;
|
||||||
}
|
}
|
||||||
[SuppressMessage("Microsoft.Portability", "CA1900:ValueTypeFieldsShouldBePortable", MessageId = "ModifiedTimeDate")]
|
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 2)]
|
[StructLayout(LayoutKind.Explicit, Pack = 2)]
|
||||||
public partial struct TW_FILESYSTEM_LEGACY
|
public partial struct TW_FILESYSTEM_LEGACY
|
||||||
{
|
{
|
||||||
@@ -2251,7 +2251,7 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public uint Flags;
|
public uint Flags;
|
||||||
public uint Length;
|
public uint Length;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr TheMem;
|
public IntPtr TheMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2282,7 +2282,7 @@ namespace TWAINWorkingGroup
|
|||||||
public UInt64 BytesWritten;
|
public UInt64 BytesWritten;
|
||||||
public UInt64 MemoryFlags;
|
public UInt64 MemoryFlags;
|
||||||
public UInt64 MemoryLength;
|
public UInt64 MemoryLength;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr MemoryTheMem;
|
public IntPtr MemoryTheMem;
|
||||||
}
|
}
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
@@ -2369,11 +2369,11 @@ namespace TWAINWorkingGroup
|
|||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
public partial struct TW_PASSTHRU
|
public partial struct TW_PASSTHRU
|
||||||
{
|
{
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr pCommand;
|
public IntPtr pCommand;
|
||||||
public uint CommandBytes;
|
public uint CommandBytes;
|
||||||
public int Direction;
|
public int Direction;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr pData;
|
public IntPtr pData;
|
||||||
public uint DataBytes;
|
public uint DataBytes;
|
||||||
public uint DataBytesXfered;
|
public uint DataBytesXfered;
|
||||||
@@ -2492,7 +2492,7 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public TW_STATUS Status;
|
public TW_STATUS Status;
|
||||||
public uint Size;
|
public uint Size;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr UTF8string;
|
public IntPtr UTF8string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2504,10 +2504,10 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public uint SizeOf;
|
public uint SizeOf;
|
||||||
public ushort CommunicationManager;
|
public ushort CommunicationManager;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr Send;
|
public IntPtr Send;
|
||||||
public uint SendSize;
|
public uint SendSize;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr Receive;
|
public IntPtr Receive;
|
||||||
public uint ReceiveSize;
|
public uint ReceiveSize;
|
||||||
}
|
}
|
||||||
@@ -2520,7 +2520,7 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public ushort ShowUI;
|
public ushort ShowUI;
|
||||||
public ushort ModalUI;
|
public ushort ModalUI;
|
||||||
[SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
|
|
||||||
public IntPtr hParent;
|
public IntPtr hParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ using System.Diagnostics;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TWAINWorkingGroup;
|
using TWAINWorkingGroup;
|
||||||
@@ -330,6 +331,34 @@ namespace NTwain
|
|||||||
return _twain.DatUserinterface(DG.CONTROL, MSG.ENABLEDS, ref ui);
|
return _twain.DatUserinterface(DG.CONTROL, MSG.ENABLEDS, ref ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads information relating to the last capture run.
|
||||||
|
/// Only valid on state 4 after a capture.
|
||||||
|
/// </summary>
|
||||||
|
public Metrics GetMetrics()
|
||||||
|
{
|
||||||
|
TW_METRICS twmetrics = default;
|
||||||
|
twmetrics.SizeOf = (uint)Marshal.SizeOf(twmetrics);
|
||||||
|
var sts = _twain.DatMetrics(DG.CONTROL, MSG.GET, ref twmetrics);
|
||||||
|
if (sts == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
return new Metrics
|
||||||
|
{
|
||||||
|
ReturnCode = sts,
|
||||||
|
Images = (int)twmetrics.ImageCount,
|
||||||
|
Sheets = (int)twmetrics.SheetCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return new Metrics { ReturnCode = sts };
|
||||||
|
}
|
||||||
|
|
||||||
|
//public sts SetTwainDirectTask()
|
||||||
|
//{
|
||||||
|
// TW_TWAINDIRECT task = default;
|
||||||
|
// var sts = _twain.DatTwaindirect(DG.CONTROL, MSG.SETTASK, ref task);
|
||||||
|
// return sts;
|
||||||
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user