mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Progress testing default DS idea.
This commit is contained in:
parent
c793ae8e57
commit
ca298f1f77
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain</PackageId>
|
||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
||||
<TargetFrameworks>net462;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0;net462;</TargetFrameworks>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
@ -51,7 +51,7 @@ namespace NTwain.Triplets
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session._appIdentityLegacy;
|
||||
var app = Session._appIdentity;
|
||||
TW_IDENTITY_LEGACY dummy = default;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
@ -64,11 +64,11 @@ namespace NTwain.Triplets
|
||||
}
|
||||
//else if (TwainPlatform.IsLinux)
|
||||
//{
|
||||
// var app = Session._appIdentityLegacy;
|
||||
// var app = Session._appIdentity;
|
||||
//}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
var app = Session._appIdentityOSX;
|
||||
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
||||
TW_IDENTITY_MACOSX dummy = default;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
|
@ -17,14 +17,15 @@ namespace NTwain.Triplets
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
/// <returns></returns>
|
||||
public STS OpenDS(ref TW_IDENTITY_LEGACY ds)
|
||||
public STS OpenDS(TW_IDENTITY_LEGACY ds) // not a ref on purpose
|
||||
{
|
||||
STS rc;
|
||||
if ((rc = DoIt(MSG.OPENDS, ref ds, true)) == STS.SUCCESS)
|
||||
{
|
||||
Session._currentDS = ds;
|
||||
Session.State = STATE.S4;
|
||||
//// determine memory mgmt routines used
|
||||
//if ((((DG)Session._appIdentityLegacy.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||
//if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||
//{
|
||||
// TW_ENTRYPOINT_DELEGATES entry = default;
|
||||
// if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
||||
@ -36,29 +37,44 @@ namespace NTwain.Triplets
|
||||
return rc;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Closes the currently open DS.
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//public STS CloseDS(ref IntPtr hwnd)
|
||||
//{
|
||||
// STS rc;
|
||||
// if ((rc = DoIt(MSG.CLOSEDSM, ref hwnd)) == STS.SUCCESS)
|
||||
// {
|
||||
// Session._hwnd = IntPtr.Zero;
|
||||
// Session._entryPoint = default;
|
||||
// Session.State = STATE.S2;
|
||||
// }
|
||||
// return rc;
|
||||
//}
|
||||
/// <summary>
|
||||
/// Closes the currently open DS.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public STS CloseDS()
|
||||
{
|
||||
STS rc;
|
||||
var ds = Session._currentDS;
|
||||
if ((rc = DoIt(MSG.CLOSEDS, ref ds, true)) == STS.SUCCESS)
|
||||
{
|
||||
Session._currentDS = default;
|
||||
Session.State = STATE.S3;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the TWAIN source selector dialog
|
||||
/// to choose the default source.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public STS UserSelect()
|
||||
{
|
||||
STS rc;
|
||||
var ds = Session._defaultDS;
|
||||
if ((rc = DoIt(MSG.USERSELECT, ref ds, true)) == STS.SUCCESS)
|
||||
{
|
||||
Session._defaultDS = ds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
STS DoIt(MSG msg, ref TW_IDENTITY_LEGACY ds, bool updateSource)
|
||||
STS DoIt(MSG msg, ref TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session._appIdentityLegacy;
|
||||
var app = Session._appIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||
@ -67,14 +83,10 @@ namespace NTwain.Triplets
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||
}
|
||||
if (updateSource && rc == STS.SUCCESS)
|
||||
{
|
||||
Session._dsIdentityLegacy = ds;
|
||||
}
|
||||
}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
var app = Session._appIdentityOSX;
|
||||
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
||||
TW_IDENTITY_MACOSX osxds = ds;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
@ -84,11 +96,7 @@ namespace NTwain.Triplets
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwaindsmDsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref osxds);
|
||||
}
|
||||
if (updateSource && rc == STS.SUCCESS)
|
||||
{
|
||||
Session._dsIdentityOSX = osxds;
|
||||
Session._dsIdentityLegacy = osxds;
|
||||
}
|
||||
ds = osxds;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
@ -24,8 +24,11 @@ namespace NTwain.Triplets
|
||||
{
|
||||
Session._hwnd = hwnd;
|
||||
Session.State = STATE.S3;
|
||||
|
||||
// todo: get default source
|
||||
|
||||
// determine memory mgmt routines used
|
||||
if ((((DG)Session._appIdentityLegacy.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||
if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||
{
|
||||
TW_ENTRYPOINT_DELEGATES entry = default;
|
||||
if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
||||
@ -60,7 +63,7 @@ namespace NTwain.Triplets
|
||||
var rc = STS.FAILURE;
|
||||
if (TwainPlatform.IsWindows)
|
||||
{
|
||||
var app = Session._appIdentityLegacy;
|
||||
var app = Session._appIdentity;
|
||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
@ -69,17 +72,17 @@ namespace NTwain.Triplets
|
||||
{
|
||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
}
|
||||
if (rc == STS.SUCCESS) Session._appIdentityLegacy = app;
|
||||
if (rc == STS.SUCCESS) Session._appIdentity = app;
|
||||
}
|
||||
//else if (TwainPlatform.IsLinux)
|
||||
//{
|
||||
// var app = Session._appIdentityLegacy;
|
||||
// var app = Session._appIdentity;
|
||||
// rc = (STS)NativeMethods.LinuxDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
// if (rc == STS.SUCCESS) Session._appIdentityLegacy = app;
|
||||
// if (rc == STS.SUCCESS) Session._appIdentity = app;
|
||||
//}
|
||||
else if (TwainPlatform.IsMacOSX)
|
||||
{
|
||||
var app = Session._appIdentityOSX;
|
||||
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
||||
if (TwainPlatform.PreferLegacyDSM)
|
||||
{
|
||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||
@ -90,8 +93,7 @@ namespace NTwain.Triplets
|
||||
}
|
||||
if (rc == STS.SUCCESS)
|
||||
{
|
||||
Session._appIdentityOSX = app;
|
||||
Session._appIdentityLegacy = app;
|
||||
Session._appIdentity = app;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
@ -21,18 +21,20 @@ namespace NTwain
|
||||
/// <summary>
|
||||
/// Gets the app identity.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY AppIdentity => _appIdentityLegacy;
|
||||
internal TW_IDENTITY_LEGACY _appIdentityLegacy;
|
||||
//internal TW_IDENTITY _appIdentity;
|
||||
internal TW_IDENTITY_MACOSX _appIdentityOSX;
|
||||
public TW_IDENTITY_LEGACY AppIdentity => _appIdentity;
|
||||
internal TW_IDENTITY_LEGACY _appIdentity;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current data source.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY DSIdentity => _dsIdentityLegacy;
|
||||
internal TW_IDENTITY_LEGACY _dsIdentityLegacy;
|
||||
//internal TW_IDENTITY _dsIdentity;
|
||||
internal TW_IDENTITY_MACOSX _dsIdentityOSX;
|
||||
public TW_IDENTITY_LEGACY CurrentDS => _currentDS;
|
||||
internal TW_IDENTITY_LEGACY _currentDS;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default data source.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY DefaultDS => _defaultDS;
|
||||
internal TW_IDENTITY_LEGACY _defaultDS;
|
||||
|
||||
private STATE _state = STATE.S1;
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace NTwain
|
||||
__encodingRegistered = true;
|
||||
}
|
||||
|
||||
_appIdentityLegacy = new()
|
||||
_appIdentity; = new()
|
||||
{
|
||||
Manufacturer = companyName,
|
||||
ProductFamily = productFamily,
|
||||
@ -76,8 +76,8 @@ namespace NTwain
|
||||
MinorNum = (ushort)productVersion.Minor,
|
||||
}
|
||||
};
|
||||
//if (TwainPlatform.IsLinux) _appIdentity = _appIdentityLegacy;
|
||||
if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentityLegacy;
|
||||
//if (TwainPlatform.IsLinux) _appIdentity = _appIdentity;
|
||||
if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentity;;
|
||||
|
||||
DGControl = new DGControl(this);
|
||||
DGImage = new DGImage(this);
|
||||
|
Loading…
Reference in New Issue
Block a user