mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-29 23:22:07 +08:00
Added custom ds data triplets.
This commit is contained in:
parent
1718aaef48
commit
7522bdf696
@ -87,7 +87,7 @@ namespace NTwain.Data
|
||||
TW_UINT32 _reserved;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
partial struct TW_CALLBACK
|
||||
{
|
||||
@ -142,8 +142,8 @@ namespace NTwain.Data
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
partial struct TW_CUSTOMDSDATA
|
||||
{
|
||||
TW_UINT32 _infoLength;
|
||||
TW_HANDLE _hData;
|
||||
public TW_UINT32 InfoLength;
|
||||
public TW_HANDLE hData;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2),
|
||||
@ -154,7 +154,7 @@ namespace NTwain.Data
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String255)]
|
||||
string _deviceName;
|
||||
|
||||
|
||||
TW_UINT32 _batteryMinutes;
|
||||
TW_INT16 _batteryPercentage;
|
||||
TW_INT32 _powerSupply;
|
||||
@ -203,7 +203,7 @@ namespace NTwain.Data
|
||||
TW_UINT16 _returnCode;
|
||||
// item should be TW_UINTPTR but it's easier to work with intptr
|
||||
//TW_UINTPTR _item;
|
||||
TW_HANDLE _item;
|
||||
TW_HANDLE _item;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
@ -316,10 +316,10 @@ namespace NTwain.Data
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)]
|
||||
string _manufacturer;
|
||||
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)]
|
||||
string _productFamily;
|
||||
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)]
|
||||
string _productName;
|
||||
}
|
||||
@ -355,7 +355,7 @@ namespace NTwain.Data
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
TW_INT16[] _bitsPerSample;
|
||||
|
||||
|
||||
TW_INT16 _bitsPerPixel;
|
||||
TW_BOOL _planar;
|
||||
TW_INT16 _pixelType;
|
||||
|
@ -976,22 +976,7 @@ namespace NTwain.Data
|
||||
|
||||
// public TW_FIX32[] Samples { get { return _samples; } }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Allows for a data source and application to pass custom data to each other.
|
||||
/// </summary>
|
||||
public partial struct TW_CUSTOMDSDATA
|
||||
{
|
||||
/// <summary>
|
||||
/// Length, in bytes, of data.
|
||||
/// </summary>
|
||||
public uint InfoLength { get { return _infoLength; } set { _infoLength = value; } }
|
||||
/// <summary>
|
||||
/// Handle to memory containing <see cref="InfoLength"/> bytes of data.
|
||||
/// </summary>
|
||||
public IntPtr Data { get { return _hData; } set { _hData = value; } }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Provides information about the Event that was raised by the Source. The Source should only fill
|
||||
/// in those fields applicable to the Event. The Application must only read those fields applicable to
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using NTwain.Data;
|
||||
|
||||
@ -93,6 +94,65 @@ namespace NTwain
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the opaque source settings (aka TW_CUSTOMDSDATA) of this source if supported.
|
||||
/// </summary>
|
||||
public byte[] CustomDSData
|
||||
{
|
||||
// TODO: check if memory mgmt is correct
|
||||
get
|
||||
{
|
||||
byte[] value = null;
|
||||
|
||||
TW_CUSTOMDSDATA data = default;
|
||||
if (Session.DGControl.CustomDSData.Get(ref data) == ReturnCode.Success && data.InfoLength > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = new byte[data.InfoLength];
|
||||
var ptr = Session.Config.MemoryManager.Lock(data.hData);
|
||||
Marshal.Copy(ptr, value, 0, (int)data.InfoLength);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Session.Config.MemoryManager.Unlock(data.hData);
|
||||
Session.Config.MemoryManager.Free(data.hData);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.Length > 0)
|
||||
{
|
||||
var data = new TW_CUSTOMDSDATA
|
||||
{
|
||||
InfoLength = (uint)value.Length
|
||||
};
|
||||
try
|
||||
{
|
||||
data.hData = Session.Config.MemoryManager.Allocate(data.InfoLength);
|
||||
var ptr = Session.Config.MemoryManager.Lock(data.hData);
|
||||
Marshal.Copy(value, 0, ptr, value.Length);
|
||||
var rc = Session.DGControl.CustomDSData.Set(ref data);
|
||||
if (rc != ReturnCode.Success)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (data.hData != IntPtr.Zero)
|
||||
{
|
||||
Session.Config.MemoryManager.Unlock(data.hData);
|
||||
Session.Config.MemoryManager.Free(data.hData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="System.String"/> that represents this instance.
|
||||
/// </summary>
|
||||
|
66
src/NTwain/Triplets/Control/CustomDSData.cs
Normal file
66
src/NTwain/Triplets/Control/CustomDSData.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using NTwain.Data;
|
||||
using NTwain.Internals;
|
||||
|
||||
namespace NTwain.Triplets.Control
|
||||
{
|
||||
sealed class CustomDSData : BaseTriplet
|
||||
{
|
||||
internal CustomDSData(TwainSession session) : base(session) { }
|
||||
|
||||
public ReturnCode Get(ref TW_CUSTOMDSDATA data)
|
||||
{
|
||||
if (Is32Bit)
|
||||
{
|
||||
if (IsWin)
|
||||
return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data);
|
||||
if (IsLinux)
|
||||
return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data);
|
||||
if (IsMac)
|
||||
return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data);
|
||||
}
|
||||
|
||||
if (IsWin)
|
||||
return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data);
|
||||
if (IsLinux)
|
||||
return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data);
|
||||
if (IsMac)
|
||||
return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data);
|
||||
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
|
||||
public ReturnCode Set(ref TW_CUSTOMDSDATA customData)
|
||||
{
|
||||
if (Is32Bit)
|
||||
{
|
||||
if (IsWin)
|
||||
return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data);
|
||||
if (IsLinux)
|
||||
return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data);
|
||||
if (IsMac)
|
||||
return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data);
|
||||
}
|
||||
|
||||
if (IsWin)
|
||||
return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data);
|
||||
if (IsLinux)
|
||||
return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data);
|
||||
if (IsMac)
|
||||
return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||
DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data);
|
||||
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
}
|
||||
}
|
@ -48,6 +48,9 @@ namespace NTwain.Triplets
|
||||
PendingXfers _pending;
|
||||
internal PendingXfers PendingXfers => _pending ?? (_pending = new PendingXfers(Session));
|
||||
|
||||
CustomDSData _custDSData;
|
||||
internal CustomDSData CustomDSData => _custDSData ?? (_custDSData = new CustomDSData(Session));
|
||||
|
||||
XferGroup _xferGroup;
|
||||
/// <summary>
|
||||
/// Gets the operations defined for DAT_XFERGROUP.
|
||||
|
@ -40,7 +40,7 @@ namespace NTwain
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for audio data group.
|
||||
/// </summary>
|
||||
DGAudio DGAudio => dgAudio ?? (dgAudio = new DGAudio(this));
|
||||
internal DGAudio DGAudio => dgAudio ?? (dgAudio = new DGAudio(this));
|
||||
|
||||
///// <summary>
|
||||
///// Gets/sets the direct triplet operation entry for custom values.
|
||||
|
Loading…
Reference in New Issue
Block a user