mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-24 08:47:06 +08:00
Added first struct selection logic by platform & bitness.
This commit is contained in:
@@ -20,6 +20,15 @@ namespace NTwain.Triplets
|
||||
protected BaseTriplet(TwainSession session)
|
||||
{
|
||||
this.Session = session ?? throw new ArgumentNullException(nameof(session));
|
||||
|
||||
// windows can always use 32bit structs even in 64bit app
|
||||
Use32BitData = session.Config.Platform == System.PlatformID.Win32NT ||
|
||||
!session.Config.Is64Bit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use 32bit data structures.
|
||||
/// </summary>
|
||||
protected readonly bool Use32BitData;
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,12 @@ namespace NTwain.Triplets.Control
|
||||
|
||||
public ReturnCode RegisterCallback(ref TW_CALLBACK callback)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||
DataGroups.Control, DataArgumentType.Callback, Message.RegisterCallback, ref callback);
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||
DataGroups.Control, DataArgumentType.Callback, Message.RegisterCallback, ref callback);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,12 @@ namespace NTwain.Triplets.Control
|
||||
|
||||
public ReturnCode RegisterCallback(ref TW_CALLBACK2 callback)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||
DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,15 @@ namespace NTwain.Triplets.Control
|
||||
sealed class DeviceEvent : BaseTriplet
|
||||
{
|
||||
internal DeviceEvent(TwainSession session) : base(session) { }
|
||||
|
||||
|
||||
public ReturnCode Get(ref TW_DEVICEEVENT sourceDeviceEvent)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||
{
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||
DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get, ref sourceDeviceEvent);
|
||||
}
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,12 @@ namespace NTwain.Triplets.Control
|
||||
public ReturnCode Get(out TW_ENTRYPOINT entryPoint)
|
||||
{
|
||||
entryPoint = new TW_ENTRYPOINT();
|
||||
return NativeMethods.Dsm32(Session.Config.App32, null,
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, null,
|
||||
DataGroups.Control, DataArgumentType.EntryPoint, Message.Get, entryPoint);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,14 @@ namespace NTwain.Triplets.Control
|
||||
|
||||
public ReturnCode CloseDS(TW_IDENTITY source)
|
||||
{
|
||||
var rc = NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
if (Use32BitData)
|
||||
{
|
||||
rc = NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source);
|
||||
}
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session.State = TwainState.S3;
|
||||
@@ -23,16 +29,24 @@ namespace NTwain.Triplets.Control
|
||||
public ReturnCode GetDefault(out TW_IDENTITY source)
|
||||
{
|
||||
source = new TW_IDENTITY();
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
|
||||
|
||||
public ReturnCode GetFirst(out TW_IDENTITY source)
|
||||
{
|
||||
source = new TW_IDENTITY();
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
|
||||
public ReturnCode GetNext(out TW_IDENTITY source)
|
||||
@@ -45,9 +59,14 @@ namespace NTwain.Triplets.Control
|
||||
public ReturnCode OpenDS(TW_IDENTITY source)
|
||||
{
|
||||
Session.StepDown(TwainState.DsmOpened);
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
var rc = NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
if (Use32BitData)
|
||||
{
|
||||
rc = NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source);
|
||||
}
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session.CurrentSource = Session.GetSourceSingleton(source);
|
||||
@@ -59,15 +78,23 @@ namespace NTwain.Triplets.Control
|
||||
|
||||
public ReturnCode Set(DataSource source)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
|
||||
public ReturnCode UserSelect(out TW_IDENTITY source)
|
||||
{
|
||||
source = new TW_IDENTITY();
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
if (Use32BitData)
|
||||
{
|
||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||
DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source);
|
||||
}
|
||||
return ReturnCode.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,14 @@ namespace NTwain.Triplets.Control
|
||||
|
||||
public ReturnCode OpenDSM(IntPtr hWnd)
|
||||
{
|
||||
var rc = NativeMethods.Dsm32(Session.Config.App32, null,
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
if (Use32BitData)
|
||||
{
|
||||
rc = NativeMethods.Dsm32(Session.Config.App32, null,
|
||||
DataGroups.Control, DataArgumentType.Parent, Message.OpenDSM, ref hWnd);
|
||||
}
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session.State = TwainState.DsmOpened;
|
||||
@@ -37,9 +43,18 @@ namespace NTwain.Triplets.Control
|
||||
|
||||
public ReturnCode CloseDSM(IntPtr hWnd)
|
||||
{
|
||||
var rc = NativeMethods.Dsm32(Session.Config.App32, null, DataGroups.Control,
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
if (Use32BitData)
|
||||
{
|
||||
rc = NativeMethods.Dsm32(Session.Config.App32, null, DataGroups.Control,
|
||||
DataArgumentType.Parent, Message.CloseDSM, ref hWnd);
|
||||
if (rc == ReturnCode.Success) Session.State = TwainState.DsmLoaded;
|
||||
}
|
||||
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
Session.State = TwainState.DsmLoaded;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user