mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Added identity calls and other ds utilities.
This commit is contained in:
@@ -8,6 +8,8 @@ namespace SampleConsole
|
|||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
|
// CONSOLE won't work yet until I got a message loop going.
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
TwainPlatform.PreferLegacyDSM = true;
|
TwainPlatform.PreferLegacyDSM = true;
|
||||||
|
|||||||
103
samples/WinForm32/Form1.Designer.cs
generated
103
samples/WinForm32/Form1.Designer.cs
generated
@@ -28,12 +28,107 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
btnSelect = new System.Windows.Forms.Button();
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
label1 = new System.Windows.Forms.Label();
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
lblDefault = new System.Windows.Forms.Label();
|
||||||
this.Text = "Form1";
|
label2 = new System.Windows.Forms.Label();
|
||||||
|
lblCurrent = new System.Windows.Forms.Label();
|
||||||
|
btnEnumSources = new System.Windows.Forms.Button();
|
||||||
|
listSources = new System.Windows.Forms.ListBox();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// btnSelect
|
||||||
|
//
|
||||||
|
btnSelect.Location = new System.Drawing.Point(12, 12);
|
||||||
|
btnSelect.Name = "btnSelect";
|
||||||
|
btnSelect.Size = new System.Drawing.Size(151, 23);
|
||||||
|
btnSelect.TabIndex = 0;
|
||||||
|
btnSelect.Text = "Select default source";
|
||||||
|
btnSelect.UseVisualStyleBackColor = true;
|
||||||
|
btnSelect.Click += btnSelect_Click;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new System.Drawing.Point(12, 51);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new System.Drawing.Size(98, 15);
|
||||||
|
label1.TabIndex = 1;
|
||||||
|
label1.Text = "Default Source = ";
|
||||||
|
//
|
||||||
|
// lblDefault
|
||||||
|
//
|
||||||
|
lblDefault.AutoSize = true;
|
||||||
|
lblDefault.Location = new System.Drawing.Point(115, 51);
|
||||||
|
lblDefault.Name = "lblDefault";
|
||||||
|
lblDefault.Size = new System.Drawing.Size(24, 15);
|
||||||
|
lblDefault.TabIndex = 2;
|
||||||
|
lblDefault.Text = "NA";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new System.Drawing.Point(12, 81);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new System.Drawing.Size(97, 15);
|
||||||
|
label2.TabIndex = 3;
|
||||||
|
label2.Text = "Current Source =";
|
||||||
|
//
|
||||||
|
// lblCurrent
|
||||||
|
//
|
||||||
|
lblCurrent.AutoSize = true;
|
||||||
|
lblCurrent.Location = new System.Drawing.Point(115, 81);
|
||||||
|
lblCurrent.Name = "lblCurrent";
|
||||||
|
lblCurrent.Size = new System.Drawing.Size(24, 15);
|
||||||
|
lblCurrent.TabIndex = 4;
|
||||||
|
lblCurrent.Text = "NA";
|
||||||
|
//
|
||||||
|
// btnEnumSources
|
||||||
|
//
|
||||||
|
btnEnumSources.Location = new System.Drawing.Point(12, 114);
|
||||||
|
btnEnumSources.Name = "btnEnumSources";
|
||||||
|
btnEnumSources.Size = new System.Drawing.Size(151, 23);
|
||||||
|
btnEnumSources.TabIndex = 5;
|
||||||
|
btnEnumSources.Text = "Enumerate sources";
|
||||||
|
btnEnumSources.UseVisualStyleBackColor = true;
|
||||||
|
btnEnumSources.Click += btnEnumSources_Click;
|
||||||
|
//
|
||||||
|
// listSources
|
||||||
|
//
|
||||||
|
listSources.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||||
|
listSources.FormattingEnabled = true;
|
||||||
|
listSources.ItemHeight = 15;
|
||||||
|
listSources.Location = new System.Drawing.Point(12, 143);
|
||||||
|
listSources.Name = "listSources";
|
||||||
|
listSources.Size = new System.Drawing.Size(279, 289);
|
||||||
|
listSources.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// Form1
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
ClientSize = new System.Drawing.Size(800, 450);
|
||||||
|
Controls.Add(listSources);
|
||||||
|
Controls.Add(btnEnumSources);
|
||||||
|
Controls.Add(lblCurrent);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(lblDefault);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(btnSelect);
|
||||||
|
Name = "Form1";
|
||||||
|
Text = "TWAIN Test";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button btnSelect;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
|
private System.Windows.Forms.Label lblDefault;
|
||||||
|
private System.Windows.Forms.Label label2;
|
||||||
|
private System.Windows.Forms.Label lblCurrent;
|
||||||
|
private System.Windows.Forms.Button btnEnumSources;
|
||||||
|
private System.Windows.Forms.ListBox listSources;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,18 @@ namespace WinForm32
|
|||||||
|
|
||||||
twain = new TwainSession(Assembly.GetExecutingAssembly().Location);
|
twain = new TwainSession(Assembly.GetExecutingAssembly().Location);
|
||||||
twain.StateChanged += Twain_StateChanged;
|
twain.StateChanged += Twain_StateChanged;
|
||||||
|
twain.DefaultSourceChanged += Twain_DefaultSourceChanged;
|
||||||
|
twain.CurrentSourceChanged += Twain_CurrentSourceChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Twain_CurrentSourceChanged(TwainSession arg1, TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
lblCurrent.Text = ds.ProductName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Twain_DefaultSourceChanged(TwainSession arg1, TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
lblDefault.Text = ds.ProductName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Twain_StateChanged(TwainSession session, STATE state)
|
private static void Twain_StateChanged(TwainSession session, STATE state)
|
||||||
@@ -35,7 +47,6 @@ namespace WinForm32
|
|||||||
var hwnd = this.Handle;
|
var hwnd = this.Handle;
|
||||||
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
||||||
Debug.WriteLine($"OpenDSM={rc}");
|
Debug.WriteLine($"OpenDSM={rc}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosing(CancelEventArgs e)
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
@@ -45,5 +56,19 @@ namespace WinForm32
|
|||||||
|
|
||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnSelect_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
twain.DGControl.Identity.UserSelect();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnEnumSources_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
listSources.Items.Clear();
|
||||||
|
foreach (var ds in twain.GetSources())
|
||||||
|
{
|
||||||
|
listSources.Items.Add(ds);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,64 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<root>
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Manufacturer} - {ProductFamily} - {ProductName} {Version} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
|
return $"{Manufacturer} - {ProductName} v{Version.MajorNum}.{Version.MinorNum} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
|
||||||
}
|
}
|
||||||
public static implicit operator TW_IDENTITY_LEGACY(TW_IDENTITY_MACOSX value) => new()
|
public static implicit operator TW_IDENTITY_LEGACY(TW_IDENTITY_MACOSX value) => new()
|
||||||
{
|
{
|
||||||
@@ -552,7 +552,7 @@ namespace TWAINWorkingGroup
|
|||||||
{
|
{
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Manufacturer} - {ProductFamily} - {ProductName} {Version} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
|
return $"{Manufacturer} - {ProductName} v{Version.MajorNum}.{Version.MinorNum} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
|
||||||
}
|
}
|
||||||
public static implicit operator TW_IDENTITY(TW_IDENTITY_LEGACY value) => new()
|
public static implicit operator TW_IDENTITY(TW_IDENTITY_LEGACY value) => new()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = STS.FAILURE;
|
var rc = STS.FAILURE;
|
||||||
if (TwainPlatform.IsWindows)
|
if (TwainPlatform.IsWindows)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentity;
|
var app = Session.AppIdentity;
|
||||||
TW_IDENTITY_LEGACY dummy = default;
|
TW_IDENTITY_LEGACY dummy = default;
|
||||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@ namespace NTwain.Triplets
|
|||||||
//}
|
//}
|
||||||
else if (TwainPlatform.IsMacOSX)
|
else if (TwainPlatform.IsMacOSX)
|
||||||
{
|
{
|
||||||
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||||
TW_IDENTITY_MACOSX dummy = default;
|
TW_IDENTITY_MACOSX dummy = default;
|
||||||
if (TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,16 +13,16 @@ namespace NTwain.Triplets
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads and opens the specified DS.
|
/// Loads and opens the specified data source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ds"></param>
|
/// <param name="ds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public STS OpenDS(TW_IDENTITY_LEGACY ds) // not a ref on purpose
|
public STS OpenDS(TW_IDENTITY_LEGACY ds) // not a ref on purpose
|
||||||
{
|
{
|
||||||
STS rc;
|
STS rc;
|
||||||
if ((rc = DoIt(MSG.OPENDS, ref ds, true)) == STS.SUCCESS)
|
if ((rc = DoIt(MSG.OPENDS, ref ds)) == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Session._currentDS = ds;
|
Session.CurrentSource = ds;
|
||||||
Session.State = STATE.S4;
|
Session.State = STATE.S4;
|
||||||
//// determine memory mgmt routines used
|
//// determine memory mgmt routines used
|
||||||
//if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
//if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||||
@@ -38,34 +38,82 @@ namespace NTwain.Triplets
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Closes the currently open DS.
|
/// Closes the currently open data source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public STS CloseDS()
|
public STS CloseDS()
|
||||||
{
|
{
|
||||||
STS rc;
|
STS rc;
|
||||||
var ds = Session._currentDS;
|
var ds = Session.CurrentSource;
|
||||||
if ((rc = DoIt(MSG.CLOSEDS, ref ds, true)) == STS.SUCCESS)
|
if ((rc = DoIt(MSG.CLOSEDS, ref ds)) == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Session._currentDS = default;
|
Session.CurrentSource = default;
|
||||||
Session.State = STATE.S3;
|
Session.State = STATE.S3;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the TWAIN source selector dialog
|
/// Opens the TWAIN data source selector dialog
|
||||||
/// to choose the default source.
|
/// to choose the default data source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public STS UserSelect()
|
public STS UserSelect()
|
||||||
{
|
{
|
||||||
STS rc;
|
STS rc;
|
||||||
var ds = Session._defaultDS;
|
var ds = Session.DefaultSource;
|
||||||
if ((rc = DoIt(MSG.USERSELECT, ref ds, true)) == STS.SUCCESS)
|
if ((rc = DoIt(MSG.USERSELECT, ref ds)) == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Session._defaultDS = ds;
|
Session.DefaultSource = ds;
|
||||||
}
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default data source.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public STS GetDefault(out TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
ds = default;
|
||||||
|
return DoIt(MSG.GETDEFAULT, ref ds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the default data source.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public STS Set(TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
STS rc;
|
||||||
|
if ((rc = DoIt(MSG.SET, ref ds)) == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Session.DefaultSource = ds;
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the first available data source in an enumerating fashion
|
||||||
|
/// (use <see cref="GetNext"/> for subsequent ones).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public STS GetFirst(out TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
ds = default;
|
||||||
|
return DoIt(MSG.GETFIRST, ref ds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the next available data source in an enumerating fashion (after using <see cref="GetFirst"/>).
|
||||||
|
/// Ends when return values is <see cref="STS.ENDOFLIST"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public STS GetNext(out TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
ds = default;
|
||||||
|
return DoIt(MSG.GETNEXT, ref ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,7 +122,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = STS.FAILURE;
|
var rc = STS.FAILURE;
|
||||||
if (TwainPlatform.IsWindows)
|
if (TwainPlatform.IsWindows)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentity;
|
var app = Session.AppIdentity;
|
||||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
rc = (STS)NativeMethods.WindowsTwain32DsmEntryIdentity(ref app, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, msg, ref ds);
|
||||||
@@ -86,7 +134,7 @@ namespace NTwain.Triplets
|
|||||||
}
|
}
|
||||||
else if (TwainPlatform.IsMacOSX)
|
else if (TwainPlatform.IsMacOSX)
|
||||||
{
|
{
|
||||||
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||||
TW_IDENTITY_MACOSX osxds = ds;
|
TW_IDENTITY_MACOSX osxds = ds;
|
||||||
if (TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,10 +25,14 @@ namespace NTwain.Triplets
|
|||||||
Session._hwnd = hwnd;
|
Session._hwnd = hwnd;
|
||||||
Session.State = STATE.S3;
|
Session.State = STATE.S3;
|
||||||
|
|
||||||
// todo: get default source
|
// get default source
|
||||||
|
if (Session.DGControl.Identity.GetDefault(out TW_IDENTITY_LEGACY ds) == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Session.DefaultSource = ds;
|
||||||
|
}
|
||||||
|
|
||||||
// determine memory mgmt routines used
|
// determine memory mgmt routines used
|
||||||
if ((((DG)Session._appIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
if ((((DG)Session.AppIdentity.SupportedGroups) & DG.DSM2) == DG.DSM2)
|
||||||
{
|
{
|
||||||
TW_ENTRYPOINT_DELEGATES entry = default;
|
TW_ENTRYPOINT_DELEGATES entry = default;
|
||||||
if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
if (Session.DGControl.EntryPoint.Get(ref entry) == STS.SUCCESS)
|
||||||
@@ -63,7 +67,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = STS.FAILURE;
|
var rc = STS.FAILURE;
|
||||||
if (TwainPlatform.IsWindows)
|
if (TwainPlatform.IsWindows)
|
||||||
{
|
{
|
||||||
var app = Session._appIdentity;
|
var app = Session.AppIdentity;
|
||||||
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.Is32bit && TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwain32DsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
rc = (STS)NativeMethods.WindowsTwain32DsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
@@ -72,7 +76,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
rc = (STS)NativeMethods.WindowsTwaindsmDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
}
|
}
|
||||||
if (rc == STS.SUCCESS) Session._appIdentity = app;
|
if (rc == STS.SUCCESS) Session.AppIdentity = app;
|
||||||
}
|
}
|
||||||
//else if (TwainPlatform.IsLinux)
|
//else if (TwainPlatform.IsLinux)
|
||||||
//{
|
//{
|
||||||
@@ -82,7 +86,7 @@ namespace NTwain.Triplets
|
|||||||
//}
|
//}
|
||||||
else if (TwainPlatform.IsMacOSX)
|
else if (TwainPlatform.IsMacOSX)
|
||||||
{
|
{
|
||||||
TW_IDENTITY_MACOSX app = Session._appIdentity;
|
TW_IDENTITY_MACOSX app = Session.AppIdentity;
|
||||||
if (TwainPlatform.PreferLegacyDSM)
|
if (TwainPlatform.PreferLegacyDSM)
|
||||||
{
|
{
|
||||||
rc = (STS)NativeMethods.MacosxTwainDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
rc = (STS)NativeMethods.MacosxTwainDsmEntryParent(ref app, IntPtr.Zero, DG.CONTROL, DAT.PARENT, msg, ref hwnd);
|
||||||
@@ -93,7 +97,7 @@ namespace NTwain.Triplets
|
|||||||
}
|
}
|
||||||
if (rc == STS.SUCCESS)
|
if (rc == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Session._appIdentity = app;
|
Session.AppIdentity = app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
using NTwain.Triplets;
|
using NTwain.Triplets;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TWAINWorkingGroup;
|
using TWAINWorkingGroup;
|
||||||
|
|
||||||
namespace NTwain
|
namespace NTwain
|
||||||
@@ -14,29 +8,47 @@ namespace NTwain
|
|||||||
|
|
||||||
partial class TwainSession
|
partial class TwainSession
|
||||||
{
|
{
|
||||||
|
|
||||||
// really legacy version is the one to be used (except on mac) or
|
|
||||||
// until it doesn't work (special linux)
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the app identity.
|
/// Gets the app identity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TW_IDENTITY_LEGACY AppIdentity => _appIdentity;
|
public TW_IDENTITY_LEGACY AppIdentity
|
||||||
internal TW_IDENTITY_LEGACY _appIdentity;
|
{
|
||||||
|
get => _appIdentity;
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
_appIdentity = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TW_IDENTITY_LEGACY _appIdentity;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current data source.
|
/// Gets the current (opened) data source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TW_IDENTITY_LEGACY CurrentDS => _currentDS;
|
public TW_IDENTITY_LEGACY CurrentSource
|
||||||
internal TW_IDENTITY_LEGACY _currentDS;
|
{
|
||||||
|
get => _currentDS;
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
_currentDS = value;
|
||||||
|
CurrentSourceChanged?.Invoke(this, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TW_IDENTITY_LEGACY _currentDS;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the default data source.
|
/// Gets the default data source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TW_IDENTITY_LEGACY DefaultDS => _defaultDS;
|
public TW_IDENTITY_LEGACY DefaultSource
|
||||||
internal TW_IDENTITY_LEGACY _defaultDS;
|
{
|
||||||
|
get => _defaultDS;
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
_defaultDS = value;
|
||||||
|
DefaultSourceChanged?.Invoke(this, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TW_IDENTITY_LEGACY _defaultDS;
|
||||||
|
|
||||||
private STATE _state = STATE.S1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current TWAIN session state.
|
/// Current TWAIN session state.
|
||||||
@@ -53,11 +65,8 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
STATE _state = STATE.S1;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Fired when <see cref="State"/> changes.
|
|
||||||
/// </summary>
|
|
||||||
public event Action<TwainSession, STATE>? StateChanged;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TWAIN triplet API calls with <see cref="DG.CONTROL"/>.
|
/// TWAIN triplet API calls with <see cref="DG.CONTROL"/>.
|
||||||
@@ -71,5 +80,24 @@ namespace NTwain
|
|||||||
/// TWAIN triplet API calls with <see cref="DG.AUDIO"/>.
|
/// TWAIN triplet API calls with <see cref="DG.AUDIO"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DGAudio DGAudio { get; }
|
public DGAudio DGAudio { get; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires when <see cref="State"/> changes.
|
||||||
|
/// </summary>
|
||||||
|
public event Action<TwainSession, STATE>? StateChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires when <see cref="DefaultSource"/> changes.
|
||||||
|
/// </summary>
|
||||||
|
public event Action<TwainSession, TW_IDENTITY_LEGACY>? DefaultSourceChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires when <see cref="CurrentSource"/> changes.
|
||||||
|
/// </summary>
|
||||||
|
public event Action<TwainSession, TW_IDENTITY_LEGACY>? CurrentSourceChanged;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/NTwain/TwainSession.Sources.cs
Normal file
25
src/NTwain/TwainSession.Sources.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using NTwain.Triplets;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TWAINWorkingGroup;
|
||||||
|
|
||||||
|
namespace NTwain
|
||||||
|
{
|
||||||
|
// this file contains data source utilities
|
||||||
|
|
||||||
|
partial class TwainSession
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all available sources.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<TW_IDENTITY_LEGACY> GetSources()
|
||||||
|
{
|
||||||
|
var rc = DGControl.Identity.GetFirst(out TW_IDENTITY_LEGACY ds);
|
||||||
|
while (rc == STS.SUCCESS)
|
||||||
|
{
|
||||||
|
yield return ds;
|
||||||
|
rc = DGControl.Identity.GetNext(out ds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using NTwain.Triplets;
|
using NTwain.Triplets;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using TWAINWorkingGroup;
|
using TWAINWorkingGroup;
|
||||||
@@ -59,7 +60,7 @@ namespace NTwain
|
|||||||
__encodingRegistered = true;
|
__encodingRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_appIdentity; = new()
|
_appIdentity = new()
|
||||||
{
|
{
|
||||||
Manufacturer = companyName,
|
Manufacturer = companyName,
|
||||||
ProductFamily = productFamily,
|
ProductFamily = productFamily,
|
||||||
@@ -76,8 +77,6 @@ namespace NTwain
|
|||||||
MinorNum = (ushort)productVersion.Minor,
|
MinorNum = (ushort)productVersion.Minor,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//if (TwainPlatform.IsLinux) _appIdentity = _appIdentity;
|
|
||||||
if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentity;;
|
|
||||||
|
|
||||||
DGControl = new DGControl(this);
|
DGControl = new DGControl(this);
|
||||||
DGImage = new DGImage(this);
|
DGImage = new DGImage(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user