mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +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)
|
protected BaseTriplet(TwainSession session)
|
||||||
{
|
{
|
||||||
this.Session = session ?? throw new ArgumentNullException(nameof(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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,13 @@ namespace NTwain.Triplets.Control
|
|||||||
internal Callback(TwainSession session) : base(session) { }
|
internal Callback(TwainSession session) : base(session) { }
|
||||||
|
|
||||||
public ReturnCode RegisterCallback(ref TW_CALLBACK callback)
|
public ReturnCode RegisterCallback(ref TW_CALLBACK callback)
|
||||||
|
{
|
||||||
|
if (Use32BitData)
|
||||||
{
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||||
DataGroups.Control, DataArgumentType.Callback, Message.RegisterCallback, ref callback);
|
DataGroups.Control, DataArgumentType.Callback, Message.RegisterCallback, ref callback);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,13 @@ namespace NTwain.Triplets.Control
|
|||||||
internal Callback2(TwainSession session) : base(session) { }
|
internal Callback2(TwainSession session) : base(session) { }
|
||||||
|
|
||||||
public ReturnCode RegisterCallback(ref TW_CALLBACK2 callback)
|
public ReturnCode RegisterCallback(ref TW_CALLBACK2 callback)
|
||||||
|
{
|
||||||
|
if (Use32BitData)
|
||||||
{
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||||
DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback);
|
DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,13 @@ namespace NTwain.Triplets.Control
|
|||||||
internal DeviceEvent(TwainSession session) : base(session) { }
|
internal DeviceEvent(TwainSession session) : base(session) { }
|
||||||
|
|
||||||
public ReturnCode Get(ref TW_DEVICEEVENT sourceDeviceEvent)
|
public ReturnCode Get(ref TW_DEVICEEVENT sourceDeviceEvent)
|
||||||
|
{
|
||||||
|
if (Use32BitData)
|
||||||
{
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
return NativeMethods.Dsm32(Session.Config.App32, Session.CurrentSource.Identity,
|
||||||
DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get, ref sourceDeviceEvent);
|
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)
|
public ReturnCode Get(out TW_ENTRYPOINT entryPoint)
|
||||||
{
|
{
|
||||||
entryPoint = new TW_ENTRYPOINT();
|
entryPoint = new TW_ENTRYPOINT();
|
||||||
|
if (Use32BitData)
|
||||||
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, null,
|
return NativeMethods.Dsm32(Session.Config.App32, null,
|
||||||
DataGroups.Control, DataArgumentType.EntryPoint, Message.Get, entryPoint);
|
DataGroups.Control, DataArgumentType.EntryPoint, Message.Get, entryPoint);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,14 @@ namespace NTwain.Triplets.Control
|
|||||||
|
|
||||||
public ReturnCode CloseDS(TW_IDENTITY source)
|
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);
|
DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
Session.State = TwainState.S3;
|
Session.State = TwainState.S3;
|
||||||
@@ -23,17 +29,25 @@ namespace NTwain.Triplets.Control
|
|||||||
public ReturnCode GetDefault(out TW_IDENTITY source)
|
public ReturnCode GetDefault(out TW_IDENTITY source)
|
||||||
{
|
{
|
||||||
source = new TW_IDENTITY();
|
source = new TW_IDENTITY();
|
||||||
|
if (Use32BitData)
|
||||||
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||||
DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source);
|
DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ReturnCode GetFirst(out TW_IDENTITY source)
|
public ReturnCode GetFirst(out TW_IDENTITY source)
|
||||||
{
|
{
|
||||||
source = new TW_IDENTITY();
|
source = new TW_IDENTITY();
|
||||||
|
if (Use32BitData)
|
||||||
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||||
DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source);
|
DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
|
|
||||||
public ReturnCode GetNext(out TW_IDENTITY source)
|
public ReturnCode GetNext(out TW_IDENTITY source)
|
||||||
{
|
{
|
||||||
@@ -45,9 +59,14 @@ namespace NTwain.Triplets.Control
|
|||||||
public ReturnCode OpenDS(TW_IDENTITY source)
|
public ReturnCode OpenDS(TW_IDENTITY source)
|
||||||
{
|
{
|
||||||
Session.StepDown(TwainState.DsmOpened);
|
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);
|
DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
Session.CurrentSource = Session.GetSourceSingleton(source);
|
Session.CurrentSource = Session.GetSourceSingleton(source);
|
||||||
@@ -58,16 +77,24 @@ namespace NTwain.Triplets.Control
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ReturnCode Set(DataSource source)
|
public ReturnCode Set(DataSource source)
|
||||||
|
{
|
||||||
|
if (Use32BitData)
|
||||||
{
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||||
DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity);
|
DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
|
|
||||||
public ReturnCode UserSelect(out TW_IDENTITY source)
|
public ReturnCode UserSelect(out TW_IDENTITY source)
|
||||||
{
|
{
|
||||||
source = new TW_IDENTITY();
|
source = new TW_IDENTITY();
|
||||||
|
if (Use32BitData)
|
||||||
|
{
|
||||||
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
return NativeMethods.Dsm32(Session.Config.App32, IntPtr.Zero,
|
||||||
DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source);
|
DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source);
|
||||||
}
|
}
|
||||||
|
return ReturnCode.Failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,14 @@ namespace NTwain.Triplets.Control
|
|||||||
|
|
||||||
public ReturnCode OpenDSM(IntPtr hWnd)
|
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);
|
DataGroups.Control, DataArgumentType.Parent, Message.OpenDSM, ref hWnd);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
Session.State = TwainState.DsmOpened;
|
Session.State = TwainState.DsmOpened;
|
||||||
@@ -37,9 +43,18 @@ namespace NTwain.Triplets.Control
|
|||||||
|
|
||||||
public ReturnCode CloseDSM(IntPtr hWnd)
|
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);
|
DataArgumentType.Parent, Message.CloseDSM, ref hWnd);
|
||||||
if (rc == ReturnCode.Success) Session.State = TwainState.DsmLoaded;
|
}
|
||||||
|
|
||||||
|
if (rc == ReturnCode.Success)
|
||||||
|
{
|
||||||
|
Session.State = TwainState.DsmLoaded;
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user