mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Added DAT_XFERGROUP calls
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
This is a library created to make working with
|
This is a library created to make working with
|
||||||
[TWAIN](http://twain.org/) easier in dotnet.
|
[TWAIN](http://twain.org/) easier in dotnet.
|
||||||
This project has these goals:
|
V4 of this lib is a work in progress and has these goals:
|
||||||
|
|
||||||
* Targets latest TWAIN version (2.4 as of this writing)
|
* Targets latest TWAIN version (2.4 as of this writing)
|
||||||
* Supports all the TWAIN functions in the spec
|
* Supports all the TWAIN functions in the spec
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NTwain.Data
|
||||||
|
{
|
||||||
|
delegate ReturnCode Callback32(TW_IDENTITY origin, TW_IDENTITY destination,
|
||||||
|
DataGroups dg, DataArgumentType dat, Message msg, IntPtr data);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using NTwain.Internals;
|
||||||
|
|
||||||
|
namespace NTwain.Triplets.Control
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents <see cref="DataArgumentType.XferGroup"/>.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class XferGroup : BaseTriplet
|
||||||
|
{
|
||||||
|
internal XferGroup(TwainSession session) : base(session) { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the Data Group (the type of data) for the upcoming transfer. The Source is required to
|
||||||
|
/// only supply one of the DGs specified in the SupportedGroups field of origin.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ReturnCode Get(ref DataGroups value)
|
||||||
|
{
|
||||||
|
if (Is32Bit)
|
||||||
|
{
|
||||||
|
if (IsWin)
|
||||||
|
return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
|
||||||
|
if (IsLinux)
|
||||||
|
return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
|
||||||
|
if (IsMac)
|
||||||
|
return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsWin)
|
||||||
|
return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
|
||||||
|
if (IsLinux)
|
||||||
|
return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
|
||||||
|
if (IsMac)
|
||||||
|
return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
|
||||||
|
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The transfer group determines the kind of data being passed from the Source to the Application.
|
||||||
|
/// By default a TWAIN Source must default to DG_IMAGE. Currently the only other data group
|
||||||
|
/// supported is DG_AUDIO, which is a feature supported by some digital cameras.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ReturnCode Set(DataGroups value)
|
||||||
|
{
|
||||||
|
if (Is32Bit)
|
||||||
|
{
|
||||||
|
if (IsWin)
|
||||||
|
return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
|
||||||
|
if (IsLinux)
|
||||||
|
return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
|
||||||
|
if (IsMac)
|
||||||
|
return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsWin)
|
||||||
|
return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
|
||||||
|
if (IsLinux)
|
||||||
|
return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
|
||||||
|
if (IsMac)
|
||||||
|
return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
|
||||||
|
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
|
||||||
|
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,5 +38,11 @@ namespace NTwain.Triplets
|
|||||||
|
|
||||||
DeviceEvent _devEvent;
|
DeviceEvent _devEvent;
|
||||||
internal DeviceEvent DeviceEvent => _devEvent ?? (_devEvent = new DeviceEvent(Session));
|
internal DeviceEvent DeviceEvent => _devEvent ?? (_devEvent = new DeviceEvent(Session));
|
||||||
|
|
||||||
|
XferGroup _xferGroup;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the operations defined for DAT_XFERGROUP.
|
||||||
|
/// </summary>
|
||||||
|
public XferGroup XferGroup => _xferGroup ?? (_xferGroup = new XferGroup(Session));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ using System.Threading;
|
|||||||
|
|
||||||
namespace NTwain
|
namespace NTwain
|
||||||
{
|
{
|
||||||
//[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
delegate ReturnCode CallbackDelegate(TW_IDENTITY origin, TW_IDENTITY destination,
|
|
||||||
DataGroups dg, DataArgumentType dat, Message msg, IntPtr data);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Manages a TWAIN session.
|
/// Manages a TWAIN session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,7 +22,7 @@ namespace NTwain
|
|||||||
// cache generated twain sources so if you get same source from same session it'll return the same object
|
// cache generated twain sources so if you get same source from same session it'll return the same object
|
||||||
readonly Dictionary<string, DataSource> _ownedSources = new Dictionary<string, DataSource>();
|
readonly Dictionary<string, DataSource> _ownedSources = new Dictionary<string, DataSource>();
|
||||||
// need to keep delegate around to prevent GC?
|
// need to keep delegate around to prevent GC?
|
||||||
readonly CallbackDelegate _callbackDelegate;
|
readonly Callback32 _callback32Delegate;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,7 +37,7 @@ namespace NTwain
|
|||||||
case PlatformID.MacOSX:
|
case PlatformID.MacOSX:
|
||||||
case PlatformID.Unix:
|
case PlatformID.Unix:
|
||||||
default:
|
default:
|
||||||
_callbackDelegate = new CallbackDelegate(Handle32BitCallback);
|
_callback32Delegate = new Callback32(Handle32BitCallback);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +103,8 @@ namespace NTwain
|
|||||||
|
|
||||||
internal void RegisterCallback()
|
internal void RegisterCallback()
|
||||||
{
|
{
|
||||||
var callbackPtr = Marshal.GetFunctionPointerForDelegate(_callbackDelegate);
|
// TODO: support other platforms
|
||||||
|
var callbackPtr = Marshal.GetFunctionPointerForDelegate(_callback32Delegate);
|
||||||
|
|
||||||
// try new callback first
|
// try new callback first
|
||||||
var cb2 = new TW_CALLBACK2 { CallBackProc = callbackPtr };
|
var cb2 = new TW_CALLBACK2 { CallBackProc = callbackPtr };
|
||||||
|
|||||||
Reference in New Issue
Block a user