Compare commits

...

16 Commits

Author SHA1 Message Date
Eugene Wang
c5e2960678 Version bump to 3.7.5 for #62 2024-07-12 08:04:12 -04:00
Eugene Wang
bf2bd6d029
Merge pull request #62 from rosswc-tempe/fix-duplicate-enum-values
Fix duplicate values in SupportedSize enum
2024-07-12 08:01:28 -04:00
Clement
bc8b257ccb Fix duplicate values in SupportedSize enum 2024-07-10 17:30:29 -07:00
Eugene Wang
e7dffaa9b5 Add strong name #30 2024-02-28 07:42:19 -05:00
Eugene Wang
207a59e2b1 Version bump to 3.7.3 2023-11-08 19:11:46 -05:00
Eugene Wang
3f30c4210e
Merge pull request #35 from cyanfish/v3
Add a TransferCanceled event
2023-11-08 19:08:11 -05:00
Eugene Wang
705d876382
Merge pull request #50 from GavinRigsby/v3
Add Custom Capabilities Extension
2023-11-08 19:06:41 -05:00
Gavin Rigsby
ee417b7377 Remove Unneeded Code 2023-11-08 11:21:14 -08:00
Gavin Rigsby
d3bd1db863 Added CapabilitiesExt.cs to handle custom capabilities if present in CapSupportedCaps 2023-11-08 10:57:01 -08:00
Ben Olden-Cooligan
3807f69584 Add a TransferCanceled event 2023-03-10 13:31:04 -08:00
Eugene Wang
25b612633c No code change, just added builds for net462 and net6.0-windows and removed net3.5. 2022-08-06 11:39:23 -04:00
Eugene Wang
0902f59597 #24 fixes dll file version being incorrect. 2021-10-06 20:27:50 -04:00
Eugene Wang
06eb14545b Add net5.0-windows build on x86 apps for now. 2021-02-02 12:03:48 -05:00
Eugene Wang
2e3f7422df Update to new csproj type and got rid of old 3.5 proj and. 2021-02-02 11:30:54 -05:00
Eugene Wang
6a0ee44eee Updated nuspec urls. 2018-11-30 14:10:53 -05:00
Eugene Wang
bbc81da779 New 3.6 build done in github with fixes for mistakes discovered in v4 dev. 2018-11-30 14:08:29 -05:00
48 changed files with 2395 additions and 675 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
.idea/
# Build results

3
Make-package.cmd Normal file
View File

@ -0,0 +1,3 @@
@echo off
dotnet build -c Release src/NTwain/NTwain.csproj
dotnet pack -c Release /p:ContinuousIntegrationBuild=true -o ./build src/NTwain/NTwain.csproj

View File

@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain", "src\NTwain\NTwain.csproj", "{0C5A6FB1-0282-4D61-8354-68DEB1515001}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NTwain", "src\NTwain\NTwain.csproj", "{0C5A6FB1-0282-4D61-8354-68DEB1515001}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain.Tests", "Tests\NTwain.Tests\NTwain.Tests.csproj", "{6B034C50-A397-435F-8DDF-677B403FEBAA}"
EndProject
@ -16,16 +16,19 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
ProjectSection(SolutionItems) = preProject
LICENSE.txt = LICENSE.txt
Make-package.cmd = Make-package.cmd
README.md = README.md
Spec\twain2.3.h = Spec\twain2.3.h
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Console", "samples\Sample.Console\Sample.Console.csproj", "{12D761EF-68DF-41CE-92EF-0C7AE81857A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain.Net35", "src\NTwain.Net35\NTwain.Net35.csproj", "{2E965494-94B0-4EC7-960C-24E5D7D04278}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B77C17FE-FD84-4FF4-9A1C-D49DB1749C9C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Net5Console", "samples\Sample.Net5Console\Sample.Net5Console.csproj", "{DDEA155C-68E9-4B42-8390-01B060DB25DB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Net5Winform", "samples\Sample.Net5Winform\Sample.Net5Winform.csproj", "{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -85,16 +88,30 @@ Global
{12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|x86.ActiveCfg = Release|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|x86.ActiveCfg = Debug|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Any CPU.Build.0 = Release|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|x86.ActiveCfg = Release|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|x86.ActiveCfg = Debug|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Debug|x86.Build.0 = Debug|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Any CPU.Build.0 = Release|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|x86.ActiveCfg = Release|Any CPU
{DDEA155C-68E9-4B42-8390-01B060DB25DB}.Release|x86.Build.0 = Release|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|x86.ActiveCfg = Debug|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Debug|x86.Build.0 = Debug|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Any CPU.Build.0 = Release|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|x86.ActiveCfg = Release|Any CPU
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -104,6 +121,11 @@ Global
{4FC243F1-318E-4FA9-9EBD-2CA3A8F35425} = {2F906640-1664-4960-93D2-A054AC6E66A3}
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D} = {2F906640-1664-4960-93D2-A054AC6E66A3}
{12D761EF-68DF-41CE-92EF-0C7AE81857A3} = {2F906640-1664-4960-93D2-A054AC6E66A3}
{DDEA155C-68E9-4B42-8390-01B060DB25DB} = {2F906640-1664-4960-93D2-A054AC6E66A3}
{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F} = {2F906640-1664-4960-93D2-A054AC6E66A3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A823206C-F8D5-491B-8B01-B9A5884FAEA1}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = NTwain.vsmdi

View File

@ -1,5 +1,7 @@
# TWAIN Application-Side Library
Note: This was migrated from [https://bitbucket.org/soukoku/ntwain/](https://bitbucket.org/soukoku/ntwain/) for v4 dev.
## Info
This is a library created to make working with [TWAIN](http://twain.org/) interface possible in dotnet.
This project has these features/goals:

View File

@ -0,0 +1,107 @@
using NTwain;
using NTwain.Data;
using System;
using System.Linq;
using System.Reflection;
using System.Threading;
namespace Sample.Net5Console
{
class Program
{
static void Main(string[] args)
{
if (PlatformInfo.Current.IsApp64Bit)
{
Console.WriteLine("[64bit]");
}
else
{
Console.WriteLine("[32bit]");
}
// just an amusing example to do twain in console without UI
ThreadPool.QueueUserWorkItem(o =>
{
try
{
DoTwainWork();
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.ToString());
}
});
Console.WriteLine("Test started, press Enter to exit.");
Console.ReadLine();
}
static readonly TwainSession twain = InitTwain();
private static TwainSession InitTwain()
{
var twain = new TwainSession(TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetExecutingAssembly()));
twain.TransferReady += (s, e) =>
{
Console.WriteLine("Got xfer ready on thread {0}.", Thread.CurrentThread.ManagedThreadId);
};
twain.DataTransferred += (s, e) =>
{
if (e.NativeData != IntPtr.Zero)
{
Console.WriteLine("SUCCESS! Got twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
else
{
Console.WriteLine("BUMMER! No twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
};
twain.SourceDisabled += (s, e) =>
{
Console.WriteLine("Source disabled on thread {0}.", Thread.CurrentThread.ManagedThreadId);
var rc = twain.CurrentSource.Close();
rc = twain.Close();
};
return twain;
}
const string SAMPLE_SOURCE = "TWAIN2 FreeImage Software Scanner";
static void DoTwainWork()
{
Console.WriteLine("Getting ready to do twain stuff on thread {0}...", Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(1000);
var rc = twain.Open();
if (rc == ReturnCode.Success)
{
var hit = twain.FirstOrDefault(s => string.Equals(s.Name, SAMPLE_SOURCE));
if (hit == null)
{
Console.WriteLine("The sample source \"" + SAMPLE_SOURCE + "\" is not installed.");
twain.Close();
}
else
{
rc = hit.Open();
if (rc == ReturnCode.Success)
{
Console.WriteLine("Starting capture from the sample source...");
rc = hit.Enable(SourceEnableMode.NoUI, false, IntPtr.Zero);
}
else
{
twain.Close();
}
}
}
else
{
Console.WriteLine("Failed to open dsm with rc={0}!", rc);
}
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sample.Net5Winform
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>scanner.ico</ApplicationIcon>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,342 @@

namespace Sample.Net5Winform
{
partial class TestForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.btnSources = new System.Windows.Forms.ToolStripDropDownButton();
this.sepSourceList = new System.Windows.Forms.ToolStripSeparator();
this.reloadSourcesListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.btnStartCapture = new System.Windows.Forms.ToolStripButton();
this.btnStopScan = new System.Windows.Forms.ToolStripButton();
this.btnSaveImage = new System.Windows.Forms.ToolStripButton();
this.panelOptions = new System.Windows.Forms.TableLayoutPanel();
this.groupDuplex = new System.Windows.Forms.GroupBox();
this.ckDuplex = new System.Windows.Forms.CheckBox();
this.groupSize = new System.Windows.Forms.GroupBox();
this.comboSize = new System.Windows.Forms.ComboBox();
this.groupDepth = new System.Windows.Forms.GroupBox();
this.comboDepth = new System.Windows.Forms.ComboBox();
this.groupDPI = new System.Windows.Forms.GroupBox();
this.comboDPI = new System.Windows.Forms.ComboBox();
this.btnAllSettings = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.toolStrip1.SuspendLayout();
this.panelOptions.SuspendLayout();
this.groupDuplex.SuspendLayout();
this.groupSize.SuspendLayout();
this.groupDepth.SuspendLayout();
this.groupDPI.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(259, 25);
this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(677, 500);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// saveFileDialog1
//
this.saveFileDialog1.FileName = "Test";
this.saveFileDialog1.Filter = "png files|*.png";
this.saveFileDialog1.Title = "Save Image";
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btnSources,
this.btnStartCapture,
this.btnStopScan,
this.btnSaveImage});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(936, 25);
this.toolStrip1.TabIndex = 2;
this.toolStrip1.Text = "toolStrip1";
//
// btnSources
//
this.btnSources.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnSources.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.sepSourceList,
this.reloadSourcesListToolStripMenuItem});
this.btnSources.Image = ((System.Drawing.Image)(resources.GetObject("btnSources.Image")));
this.btnSources.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnSources.Name = "btnSources";
this.btnSources.Size = new System.Drawing.Size(94, 22);
this.btnSources.Text = "Select &sources";
this.btnSources.DropDownOpening += new System.EventHandler(this.btnSources_DropDownOpening);
//
// sepSourceList
//
this.sepSourceList.Name = "sepSourceList";
this.sepSourceList.Size = new System.Drawing.Size(168, 6);
//
// reloadSourcesListToolStripMenuItem
//
this.reloadSourcesListToolStripMenuItem.Name = "reloadSourcesListToolStripMenuItem";
this.reloadSourcesListToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.reloadSourcesListToolStripMenuItem.Text = "&Reload sources list";
this.reloadSourcesListToolStripMenuItem.Click += new System.EventHandler(this.reloadSourcesListToolStripMenuItem_Click);
//
// btnStartCapture
//
this.btnStartCapture.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnStartCapture.Enabled = false;
this.btnStartCapture.Image = ((System.Drawing.Image)(resources.GetObject("btnStartCapture.Image")));
this.btnStartCapture.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnStartCapture.Name = "btnStartCapture";
this.btnStartCapture.Size = new System.Drawing.Size(62, 22);
this.btnStartCapture.Text = "S&tart scan";
this.btnStartCapture.Click += new System.EventHandler(this.btnStartCapture_Click);
//
// btnStopScan
//
this.btnStopScan.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnStopScan.Enabled = false;
this.btnStopScan.Image = ((System.Drawing.Image)(resources.GetObject("btnStopScan.Image")));
this.btnStopScan.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnStopScan.Name = "btnStopScan";
this.btnStopScan.Size = new System.Drawing.Size(62, 22);
this.btnStopScan.Text = "Sto&p scan";
this.btnStopScan.Click += new System.EventHandler(this.btnStopScan_Click);
//
// btnSaveImage
//
this.btnSaveImage.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.btnSaveImage.Image = ((System.Drawing.Image)(resources.GetObject("btnSaveImage.Image")));
this.btnSaveImage.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnSaveImage.Name = "btnSaveImage";
this.btnSaveImage.Size = new System.Drawing.Size(71, 22);
this.btnSaveImage.Text = "S&ave image";
this.btnSaveImage.Click += new System.EventHandler(this.btnSaveImage_Click);
//
// panelOptions
//
this.panelOptions.AutoScroll = true;
this.panelOptions.ColumnCount = 1;
this.panelOptions.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.panelOptions.Controls.Add(this.groupDuplex, 0, 3);
this.panelOptions.Controls.Add(this.groupSize, 0, 2);
this.panelOptions.Controls.Add(this.groupDepth, 0, 1);
this.panelOptions.Controls.Add(this.groupDPI, 0, 0);
this.panelOptions.Controls.Add(this.btnAllSettings, 0, 6);
this.panelOptions.Dock = System.Windows.Forms.DockStyle.Left;
this.panelOptions.Location = new System.Drawing.Point(0, 25);
this.panelOptions.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.panelOptions.Name = "panelOptions";
this.panelOptions.RowCount = 7;
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
this.panelOptions.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
this.panelOptions.Size = new System.Drawing.Size(259, 500);
this.panelOptions.TabIndex = 3;
//
// groupDuplex
//
this.groupDuplex.Controls.Add(this.ckDuplex);
this.groupDuplex.Dock = System.Windows.Forms.DockStyle.Top;
this.groupDuplex.Enabled = false;
this.groupDuplex.Location = new System.Drawing.Point(9, 231);
this.groupDuplex.Margin = new System.Windows.Forms.Padding(9, 9, 9, 9);
this.groupDuplex.Name = "groupDuplex";
this.groupDuplex.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.groupDuplex.Size = new System.Drawing.Size(241, 67);
this.groupDuplex.TabIndex = 6;
this.groupDuplex.TabStop = false;
this.groupDuplex.Text = "Duplex";
//
// ckDuplex
//
this.ckDuplex.AutoSize = true;
this.ckDuplex.Location = new System.Drawing.Point(21, 28);
this.ckDuplex.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.ckDuplex.Name = "ckDuplex";
this.ckDuplex.Size = new System.Drawing.Size(68, 19);
this.ckDuplex.TabIndex = 0;
this.ckDuplex.Text = "Enabled";
this.ckDuplex.UseVisualStyleBackColor = true;
this.ckDuplex.CheckedChanged += new System.EventHandler(this.ckDuplex_CheckedChanged);
//
// groupSize
//
this.groupSize.Controls.Add(this.comboSize);
this.groupSize.Dock = System.Windows.Forms.DockStyle.Top;
this.groupSize.Enabled = false;
this.groupSize.Location = new System.Drawing.Point(9, 157);
this.groupSize.Margin = new System.Windows.Forms.Padding(9, 9, 9, 3);
this.groupSize.Name = "groupSize";
this.groupSize.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.groupSize.Size = new System.Drawing.Size(241, 62);
this.groupSize.TabIndex = 5;
this.groupSize.TabStop = false;
this.groupSize.Text = "Size";
//
// comboSize
//
this.comboSize.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboSize.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboSize.FormattingEnabled = true;
this.comboSize.Location = new System.Drawing.Point(21, 22);
this.comboSize.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.comboSize.Name = "comboSize";
this.comboSize.Size = new System.Drawing.Size(197, 23);
this.comboSize.TabIndex = 0;
this.comboSize.SelectedIndexChanged += new System.EventHandler(this.comboSize_SelectedIndexChanged);
//
// groupDepth
//
this.groupDepth.Controls.Add(this.comboDepth);
this.groupDepth.Dock = System.Windows.Forms.DockStyle.Top;
this.groupDepth.Enabled = false;
this.groupDepth.Location = new System.Drawing.Point(9, 83);
this.groupDepth.Margin = new System.Windows.Forms.Padding(9, 9, 9, 3);
this.groupDepth.Name = "groupDepth";
this.groupDepth.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.groupDepth.Size = new System.Drawing.Size(241, 62);
this.groupDepth.TabIndex = 4;
this.groupDepth.TabStop = false;
this.groupDepth.Text = "Depth";
//
// comboDepth
//
this.comboDepth.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboDepth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboDepth.FormattingEnabled = true;
this.comboDepth.Location = new System.Drawing.Point(21, 22);
this.comboDepth.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.comboDepth.Name = "comboDepth";
this.comboDepth.Size = new System.Drawing.Size(197, 23);
this.comboDepth.TabIndex = 0;
this.comboDepth.SelectedIndexChanged += new System.EventHandler(this.comboDepth_SelectedIndexChanged);
//
// groupDPI
//
this.groupDPI.Controls.Add(this.comboDPI);
this.groupDPI.Dock = System.Windows.Forms.DockStyle.Top;
this.groupDPI.Enabled = false;
this.groupDPI.Location = new System.Drawing.Point(9, 9);
this.groupDPI.Margin = new System.Windows.Forms.Padding(9, 9, 9, 3);
this.groupDPI.Name = "groupDPI";
this.groupDPI.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.groupDPI.Size = new System.Drawing.Size(241, 62);
this.groupDPI.TabIndex = 0;
this.groupDPI.TabStop = false;
this.groupDPI.Text = "DPI";
//
// comboDPI
//
this.comboDPI.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboDPI.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboDPI.FormattingEnabled = true;
this.comboDPI.Location = new System.Drawing.Point(21, 22);
this.comboDPI.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.comboDPI.Name = "comboDPI";
this.comboDPI.Size = new System.Drawing.Size(197, 23);
this.comboDPI.TabIndex = 0;
this.comboDPI.SelectedIndexChanged += new System.EventHandler(this.comboDPI_SelectedIndexChanged);
//
// btnAllSettings
//
this.btnAllSettings.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btnAllSettings.Enabled = false;
this.btnAllSettings.Location = new System.Drawing.Point(40, 356);
this.btnAllSettings.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.btnAllSettings.Name = "btnAllSettings";
this.btnAllSettings.Size = new System.Drawing.Size(178, 27);
this.btnAllSettings.TabIndex = 7;
this.btnAllSettings.Text = "Open driver settings";
this.btnAllSettings.UseVisualStyleBackColor = true;
this.btnAllSettings.Click += new System.EventHandler(this.btnAllSettings_Click);
//
// TestForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(936, 525);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.panelOptions);
this.Controls.Add(this.toolStrip1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.Name = "TestForm";
this.Text = "Test Form";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.panelOptions.ResumeLayout(false);
this.groupDuplex.ResumeLayout(false);
this.groupDuplex.PerformLayout();
this.groupSize.ResumeLayout(false);
this.groupDepth.ResumeLayout(false);
this.groupDPI.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton btnSources;
private System.Windows.Forms.ToolStripSeparator sepSourceList;
private System.Windows.Forms.ToolStripMenuItem reloadSourcesListToolStripMenuItem;
private System.Windows.Forms.TableLayoutPanel panelOptions;
private System.Windows.Forms.GroupBox groupDPI;
private System.Windows.Forms.GroupBox groupDepth;
private System.Windows.Forms.GroupBox groupSize;
private System.Windows.Forms.GroupBox groupDuplex;
private System.Windows.Forms.ComboBox comboDPI;
private System.Windows.Forms.ComboBox comboSize;
private System.Windows.Forms.ComboBox comboDepth;
private System.Windows.Forms.ToolStripButton btnStartCapture;
private System.Windows.Forms.ToolStripButton btnStopScan;
private System.Windows.Forms.ToolStripButton btnSaveImage;
private System.Windows.Forms.CheckBox ckDuplex;
private System.Windows.Forms.Button btnAllSettings;
}
}

View File

@ -0,0 +1,421 @@
using NTwain;
using NTwain.Data;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
namespace Sample.Net5Winform
{
public partial class TestForm : Form
{
ImageCodecInfo _tiffCodecInfo;
TwainSession _twain;
bool _stopScan;
bool _loadingCaps;
#region setup & cleanup
public TestForm()
{
InitializeComponent();
if (NTwain.PlatformInfo.Current.IsApp64Bit)
{
Text = Text + " (64bit)";
}
else
{
Text = Text + " (32bit)";
}
foreach (var enc in ImageCodecInfo.GetImageEncoders())
{
if (enc.MimeType == "image/tiff") { _tiffCodecInfo = enc; break; }
}
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
SetupTwain();
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (_twain != null)
{
if (e.CloseReason == CloseReason.UserClosing && _twain.State > 4)
{
e.Cancel = true;
}
else
{
CleanupTwain();
}
}
base.OnFormClosing(e);
}
private void SetupTwain()
{
var appId = TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetEntryAssembly());
_twain = new TwainSession(appId);
_twain.StateChanged += (s, e) =>
{
PlatformInfo.Current.Log.Info("State changed to " + _twain.State + " on thread " + Thread.CurrentThread.ManagedThreadId);
};
_twain.TransferError += (s, e) =>
{
PlatformInfo.Current.Log.Info("Got xfer error on thread " + Thread.CurrentThread.ManagedThreadId);
};
_twain.DataTransferred += (s, e) =>
{
PlatformInfo.Current.Log.Info("Transferred data event on thread " + Thread.CurrentThread.ManagedThreadId);
// example on getting ext image info
var infos = e.GetExtImageInfo(ExtendedImageInfo.Camera).Where(it => it.ReturnCode == ReturnCode.Success);
foreach (var it in infos)
{
var values = it.ReadValues();
PlatformInfo.Current.Log.Info(string.Format("{0} = {1}", it.InfoID, values.FirstOrDefault()));
break;
}
// handle image data
Image img = null;
if (e.NativeData != IntPtr.Zero)
{
var stream = e.GetNativeImageStream();
if (stream != null)
{
img = Image.FromStream(stream);
}
}
else if (!string.IsNullOrEmpty(e.FileDataPath))
{
img = new Bitmap(e.FileDataPath);
}
if (img != null)
{
this.BeginInvoke(new Action(() =>
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
pictureBox1.Image = img;
}));
}
};
_twain.SourceDisabled += (s, e) =>
{
PlatformInfo.Current.Log.Info("Source disabled event on thread " + Thread.CurrentThread.ManagedThreadId);
this.BeginInvoke(new Action(() =>
{
btnStopScan.Enabled = false;
btnStartCapture.Enabled = true;
panelOptions.Enabled = true;
LoadSourceCaps();
}));
};
_twain.TransferReady += (s, e) =>
{
PlatformInfo.Current.Log.Info("Transferr ready event on thread " + Thread.CurrentThread.ManagedThreadId);
e.CancelAll = _stopScan;
};
// either set sync context and don't worry about threads during events,
// or don't and use control.invoke during the events yourself
PlatformInfo.Current.Log.Info("Setup thread = " + Thread.CurrentThread.ManagedThreadId);
_twain.SynchronizationContext = SynchronizationContext.Current;
if (_twain.State < 3)
{
// use this for internal msg loop
_twain.Open();
// use this to hook into current app loop
//_twain.Open(new WindowsFormsMessageLoopHook(this.Handle));
}
}
private void CleanupTwain()
{
if (_twain.State == 4)
{
_twain.CurrentSource.Close();
}
if (_twain.State == 3)
{
_twain.Close();
}
if (_twain.State > 2)
{
// normal close down didn't work, do hard kill
_twain.ForceStepDown(2);
}
}
#endregion
#region toolbar
private void btnSources_DropDownOpening(object sender, EventArgs e)
{
if (btnSources.DropDownItems.Count == 2)
{
ReloadSourceList();
}
}
private void reloadSourcesListToolStripMenuItem_Click(object sender, EventArgs e)
{
ReloadSourceList();
}
private void ReloadSourceList()
{
if (_twain.State >= 3)
{
while (btnSources.DropDownItems.IndexOf(sepSourceList) > 0)
{
var first = btnSources.DropDownItems[0];
first.Click -= SourceMenuItem_Click;
btnSources.DropDownItems.Remove(first);
}
foreach (var src in _twain)
{
var srcBtn = new ToolStripMenuItem(src.Name);
srcBtn.Tag = src;
srcBtn.Click += SourceMenuItem_Click;
srcBtn.Checked = _twain.CurrentSource != null && _twain.CurrentSource.Name == src.Name;
btnSources.DropDownItems.Insert(0, srcBtn);
}
}
}
void SourceMenuItem_Click(object sender, EventArgs e)
{
// do nothing if source is enabled
if (_twain.State > 4) { return; }
if (_twain.State == 4) { _twain.CurrentSource.Close(); }
foreach (var btn in btnSources.DropDownItems)
{
var srcBtn = btn as ToolStripMenuItem;
if (srcBtn != null) { srcBtn.Checked = false; }
}
var curBtn = (sender as ToolStripMenuItem);
var src = curBtn.Tag as DataSource;
if (src.Open() == ReturnCode.Success)
{
curBtn.Checked = true;
btnStartCapture.Enabled = true;
LoadSourceCaps();
}
}
private void btnStartCapture_Click(object sender, EventArgs e)
{
if (_twain.State == 4)
{
//_twain.CurrentSource.CapXferCount.Set(4);
_stopScan = false;
if (_twain.CurrentSource.Capabilities.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
{
// hide scanner ui if possible
if (_twain.CurrentSource.Enable(SourceEnableMode.NoUI, false, this.Handle) == ReturnCode.Success)
{
btnStopScan.Enabled = true;
btnStartCapture.Enabled = false;
panelOptions.Enabled = false;
}
}
else
{
if (_twain.CurrentSource.Enable(SourceEnableMode.ShowUI, true, this.Handle) == ReturnCode.Success)
{
btnStopScan.Enabled = true;
btnStartCapture.Enabled = false;
panelOptions.Enabled = false;
}
}
}
}
private void btnStopScan_Click(object sender, EventArgs e)
{
_stopScan = true;
}
private void btnSaveImage_Click(object sender, EventArgs e)
{
var img = pictureBox1.Image;
if (img != null)
{
switch (img.PixelFormat)
{
case PixelFormat.Format1bppIndexed:
saveFileDialog1.Filter = "tiff files|*.tif";
break;
default:
saveFileDialog1.Filter = "png files|*.png";
break;
}
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (saveFileDialog1.FileName.EndsWith(".tif", StringComparison.OrdinalIgnoreCase))
{
EncoderParameters tiffParam = new EncoderParameters(1);
tiffParam.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
pictureBox1.Image.Save(saveFileDialog1.FileName, _tiffCodecInfo, tiffParam);
}
else
{
pictureBox1.Image.Save(saveFileDialog1.FileName, ImageFormat.Png);
}
}
}
}
#endregion
#region cap control
private void LoadSourceCaps()
{
var src = _twain.CurrentSource;
_loadingCaps = true;
//var test = src.SupportedCaps;
if (groupDepth.Enabled = src.Capabilities.ICapPixelType.IsSupported)
{
LoadDepth(src.Capabilities.ICapPixelType);
}
if (groupDPI.Enabled = src.Capabilities.ICapXResolution.IsSupported && src.Capabilities.ICapYResolution.IsSupported)
{
LoadDPI(src.Capabilities.ICapXResolution);
}
// TODO: find out if this is how duplex works or also needs the other option
if (groupDuplex.Enabled = src.Capabilities.CapDuplexEnabled.IsSupported)
{
LoadDuplex(src.Capabilities.CapDuplexEnabled);
}
if (groupSize.Enabled = src.Capabilities.ICapSupportedSizes.IsSupported)
{
LoadPaperSize(src.Capabilities.ICapSupportedSizes);
}
btnAllSettings.Enabled = src.Capabilities.CapEnableDSUIOnly.IsSupported;
_loadingCaps = false;
}
private void LoadPaperSize(ICapWrapper<SupportedSize> cap)
{
var list = cap.GetValues().ToList();
comboSize.DataSource = list;
var cur = cap.GetCurrent();
if (list.Contains(cur))
{
comboSize.SelectedItem = cur;
}
var labelTest = cap.GetLabel();
if (!string.IsNullOrEmpty(labelTest))
{
groupSize.Text = labelTest;
}
}
private void LoadDuplex(ICapWrapper<BoolType> cap)
{
ckDuplex.Checked = cap.GetCurrent() == BoolType.True;
}
private void LoadDPI(ICapWrapper<TWFix32> cap)
{
// only allow dpi of certain values for those source that lists everything
var list = cap.GetValues().Where(dpi => (dpi % 50) == 0).ToList();
comboDPI.DataSource = list;
var cur = cap.GetCurrent();
if (list.Contains(cur))
{
comboDPI.SelectedItem = cur;
}
}
private void LoadDepth(ICapWrapper<PixelType> cap)
{
var list = cap.GetValues().ToList();
comboDepth.DataSource = list;
var cur = cap.GetCurrent();
if (list.Contains(cur))
{
comboDepth.SelectedItem = cur;
}
var labelTest = cap.GetLabel();
if (!string.IsNullOrEmpty(labelTest))
{
groupDepth.Text = labelTest;
}
}
private void comboSize_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_loadingCaps && _twain.State == 4)
{
var sel = (SupportedSize)comboSize.SelectedItem;
_twain.CurrentSource.Capabilities.ICapSupportedSizes.SetValue(sel);
}
}
private void comboDepth_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_loadingCaps && _twain.State == 4)
{
var sel = (PixelType)comboDepth.SelectedItem;
_twain.CurrentSource.Capabilities.ICapPixelType.SetValue(sel);
}
}
private void comboDPI_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_loadingCaps && _twain.State == 4)
{
var sel = (TWFix32)comboDPI.SelectedItem;
_twain.CurrentSource.Capabilities.ICapXResolution.SetValue(sel);
_twain.CurrentSource.Capabilities.ICapYResolution.SetValue(sel);
}
}
private void ckDuplex_CheckedChanged(object sender, EventArgs e)
{
if (!_loadingCaps && _twain.State == 4)
{
_twain.CurrentSource.Capabilities.CapDuplexEnabled.SetValue(ckDuplex.Checked ? BoolType.True : BoolType.False);
}
}
private void btnAllSettings_Click(object sender, EventArgs e)
{
_twain.CurrentSource.Enable(SourceEnableMode.ShowUIOnly, true, this.Handle);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -19,7 +19,7 @@ namespace Sample.WPF.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -12,7 +12,7 @@ namespace Sample.WPF.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@ -14,7 +14,8 @@
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" /></startup>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
<assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="GalaSoft.MvvmLight" publicKeyToken="0e453835af4ee6ce" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.3.0.19038" newVersion="5.3.0.19038" />
<assemblyIdentity name="GalaSoft.MvvmLight" publicKeyToken="0e453835af4ee6ce" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.3.0.19038" newVersion="5.3.0.19038"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

View File

@ -19,7 +19,7 @@ namespace Sample.Winform.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {

View File

@ -12,7 +12,7 @@ namespace Sample.Winform.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@ -12,7 +12,8 @@
<AssemblyName>Sample.Winform</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@ -77,13 +78,13 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\NTwain.Net35\NTwain.Net35.csproj">
<Project>{2e965494-94b0-4ec7-960c-24e5d7d04278}</Project>
<Name>NTwain.Net35</Name>
</ProjectReference>
<None Include="scanner.ico" />
</ItemGroup>
<ItemGroup>
<None Include="scanner.ico" />
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj">
<Project>{0c5a6fb1-0282-4d61-8354-68deb1515001}</Project>
<Name>NTwain</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -1,3 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727" sku="Client"/></startup></configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

View File

@ -1,365 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2E965494-94B0-4EC7-960C-24E5D7D04278}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NTwain</RootNamespace>
<AssemblyName>NTwain</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\NTwain\bin\Debug\Net35\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET35</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\NTwain\bin\Release\Net35\</OutputPath>
<DefineConstants>TRACE;NET35</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\NTwain\bin\Release\Net35\NTwain.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Sign.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\NTwain\Capabilities.cs">
<Link>Capabilities.cs</Link>
</Compile>
<Compile Include="..\NTwain\CapabilityReader.cs">
<Link>CapabilityReader.cs</Link>
</Compile>
<Compile Include="..\NTwain\CapWrapper.cs">
<Link>CapWrapper.cs</Link>
</Compile>
<Compile Include="..\NTwain\DataSource.cs">
<Link>DataSource.cs</Link>
</Compile>
<Compile Include="..\NTwain\DataTransferredEventArgs.cs">
<Link>DataTransferredEventArgs.cs</Link>
</Compile>
<Compile Include="..\NTwain\Data\TwainTypes.cs">
<Link>Data\TwainTypes.cs</Link>
</Compile>
<Compile Include="..\NTwain\Data\TwainTypesExtended.cs">
<Link>Data\TwainTypesExtended.cs</Link>
</Compile>
<Compile Include="..\NTwain\Data\TwainValues.cs">
<Link>Data\TwainValues.cs</Link>
</Compile>
<Compile Include="..\NTwain\Data\TypeExtensions.cs">
<Link>Data\TypeExtensions.cs</Link>
</Compile>
<Compile Include="..\NTwain\Data\ValueExtensions.cs">
<Link>Data\ValueExtensions.cs</Link>
</Compile>
<Compile Include="..\NTwain\DeviceEventArgs.cs">
<Link>DeviceEventArgs.cs</Link>
</Compile>
<Compile Include="..\NTwain\ICapabilities.cs">
<Link>ICapabilities.cs</Link>
</Compile>
<Compile Include="..\NTwain\ICapWrapper.cs">
<Link>ICapWrapper.cs</Link>
</Compile>
<Compile Include="..\NTwain\IDataSource.cs">
<Link>IDataSource.cs</Link>
</Compile>
<Compile Include="..\NTwain\ILog.cs">
<Link>ILog.cs</Link>
</Compile>
<Compile Include="..\NTwain\IMemoryManager.cs">
<Link>IMemoryManager.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\Extensions.cs">
<Link>Internals\Extensions.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\ICommittable.cs">
<Link>Internals\ICommittable.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\ImageTools.cs">
<Link>Internals\ImageTools.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\InternalMessageLoopHook.cs">
<Link>Internals\InternalMessageLoopHook.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\ITwainSessionInternal.cs">
<Link>Internals\ITwainSessionInternal.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\IWinMessageFilter.cs">
<Link>Internals\IWinMessageFilter.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\LinuxMemoryManager.cs">
<Link>Internals\LinuxMemoryManager.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\TentativeStateCommitable.cs">
<Link>Internals\TentativeStateCommitable.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\TraceLog.cs">
<Link>Internals\TraceLog.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\TransferLogic.cs">
<Link>Internals\TransferLogic.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\WindowsHook.cs">
<Link>Internals\WindowsHook.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\WinMemoryManager.cs">
<Link>Internals\WinMemoryManager.cs</Link>
</Compile>
<Compile Include="..\NTwain\Internals\WrappedManualResetEvent.cs">
<Link>Internals\WrappedManualResetEvent.cs</Link>
</Compile>
<Compile Include="..\NTwain\Interop\BITMAP.cs">
<Link>Interop\BITMAP.cs</Link>
</Compile>
<Compile Include="..\NTwain\Interop\MESSAGE.cs">
<Link>Interop\MESSAGE.cs</Link>
</Compile>
<Compile Include="..\NTwain\Interop\NativeMethods.cs">
<Link>Interop\NativeMethods.cs</Link>
</Compile>
<Compile Include="..\NTwain\Interop\TIFF.cs">
<Link>Interop\TIFF.cs</Link>
</Compile>
<Compile Include="..\NTwain\Interop\UnsafeNativeMethods.cs">
<Link>Interop\UnsafeNativeMethods.cs</Link>
</Compile>
<Compile Include="..\NTwain\IPlatformInfo.cs">
<Link>IPlatformInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\ITripletControl.cs">
<Link>ITripletControl.cs</Link>
</Compile>
<Compile Include="..\NTwain\ITwainSession.cs">
<Link>ITwainSession.cs</Link>
</Compile>
<Compile Include="..\NTwain\MessageLoopHooks.cs">
<Link>MessageLoopHooks.cs</Link>
</Compile>
<Compile Include="..\NTwain\PlatformInfo.cs">
<Link>PlatformInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\Properties\Resources.Designer.cs">
<Link>Properties\Resources.Designer.cs</Link>
<DependentUpon>Resources.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="..\NTwain\Properties\VersionInfo.cs">
<Link>Properties\VersionInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\ProtocolVersions.cs">
<Link>ProtocolVersions.cs</Link>
</Compile>
<Compile Include="..\NTwain\SourceEnableMode.cs">
<Link>SourceEnableMode.cs</Link>
</Compile>
<Compile Include="..\NTwain\State.cs">
<Link>State.cs</Link>
</Compile>
<Compile Include="..\NTwain\TransferErrorEventArgs.cs">
<Link>TransferErrorEventArgs.cs</Link>
</Compile>
<Compile Include="..\NTwain\TransferReadyEventArgs.cs">
<Link>TransferReadyEventArgs.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGAudio\DGAudio.AudioFileXfer.cs">
<Link>Triplets\DGAudio\DGAudio.AudioFileXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGAudio\DGAudio.AudioInfo.cs">
<Link>Triplets\DGAudio\DGAudio.AudioInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGAudio\DGAudio.AudioNativeXfer.cs">
<Link>Triplets\DGAudio\DGAudio.AudioNativeXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGAudio\DGAudio.cs">
<Link>Triplets\DGAudio\DGAudio.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Callback.cs">
<Link>Triplets\DGControl\DGControl.Callback.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Callback2.cs">
<Link>Triplets\DGControl\DGControl.Callback2.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Capability.cs">
<Link>Triplets\DGControl\DGControl.Capability.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.CapabilityCustom.cs">
<Link>Triplets\DGControl\DGControl.CapabilityCustom.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.cs">
<Link>Triplets\DGControl\DGControl.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.CustomDSData.cs">
<Link>Triplets\DGControl\DGControl.CustomDSData.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.DeviceEvent.cs">
<Link>Triplets\DGControl\DGControl.DeviceEvent.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.EntryPoint.cs">
<Link>Triplets\DGControl\DGControl.EntryPoint.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Event.cs">
<Link>Triplets\DGControl\DGControl.Event.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.FileSystem.cs">
<Link>Triplets\DGControl\DGControl.FileSystem.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Identity.cs">
<Link>Triplets\DGControl\DGControl.Identity.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Parent.cs">
<Link>Triplets\DGControl\DGControl.Parent.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.PassThru.cs">
<Link>Triplets\DGControl\DGControl.PassThru.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.PendingXfers.cs">
<Link>Triplets\DGControl\DGControl.PendingXfers.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.SetupFileXfer.cs">
<Link>Triplets\DGControl\DGControl.SetupFileXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.SetupMemXfer.cs">
<Link>Triplets\DGControl\DGControl.SetupMemXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Status.cs">
<Link>Triplets\DGControl\DGControl.Status.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.StatusUtf8.cs">
<Link>Triplets\DGControl\DGControl.StatusUtf8.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.UserInterface.cs">
<Link>Triplets\DGControl\DGControl.UserInterface.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.XferGroup.cs">
<Link>Triplets\DGControl\DGControl.XferGroup.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGCustom.cs">
<Link>Triplets\DGCustom.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.CieColor.cs">
<Link>Triplets\DGImage\DGImage.CieColor.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.cs">
<Link>Triplets\DGImage\DGImage.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ExtImageInfo.cs">
<Link>Triplets\DGImage\DGImage.ExtImageInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.Filter.cs">
<Link>Triplets\DGImage\DGImage.Filter.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.GrayResponse.cs">
<Link>Triplets\DGImage\DGImage.GrayResponse.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.IccProfile.cs">
<Link>Triplets\DGImage\DGImage.IccProfile.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ImageFileXfer.cs">
<Link>Triplets\DGImage\DGImage.ImageFileXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ImageInfo.cs">
<Link>Triplets\DGImage\DGImage.ImageInfo.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ImageLayout.cs">
<Link>Triplets\DGImage\DGImage.ImageLayout.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ImageMemFileXfer.cs">
<Link>Triplets\DGImage\DGImage.ImageMemFileXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ImageMemXfer.cs">
<Link>Triplets\DGImage\DGImage.ImageMemXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.ImageNativeXfer.cs">
<Link>Triplets\DGImage\DGImage.ImageNativeXfer.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.JpegCompression.cs">
<Link>Triplets\DGImage\DGImage.JpegCompression.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.Palette8.cs">
<Link>Triplets\DGImage\DGImage.Palette8.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGImage\DGImage.RgbResponse.cs">
<Link>Triplets\DGImage\DGImage.RgbResponse.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\Dsm.cs">
<Link>Triplets\Dsm.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\Dsm.Linux.cs">
<Link>Triplets\Dsm.Linux.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\Dsm.WinNew.cs">
<Link>Triplets\Dsm.WinNew.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\Dsm.WinOld.cs">
<Link>Triplets\Dsm.WinOld.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\TripletBase.cs">
<Link>Triplets\TripletBase.cs</Link>
</Compile>
<Compile Include="..\NTwain\TwainException.cs">
<Link>TwainException.cs</Link>
</Compile>
<Compile Include="..\NTwain\TwainSession.cs">
<Link>TwainSession.cs</Link>
</Compile>
<Compile Include="..\NTwain\TwainSessionInternal.cs">
<Link>TwainSessionInternal.cs</Link>
</Compile>
<Compile Include="..\NTwain\TwainStateException.cs">
<Link>TwainStateException.cs</Link>
</Compile>
<Compile Include="..\NTwain\WpfImageTools.cs">
<Link>WpfImageTools.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\NTwain\Properties\Resources.resx">
<Link>Properties\Resources.resx</Link>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="..\NTwain\Triplets\WhatsThis.txt">
<Link>Triplets\WhatsThis.txt</Link>
</None>
<None Include="Sign.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Binary file not shown.

View File

@ -0,0 +1,137 @@
using NTwain.Data;
using System;
using System.Collections.Generic;
namespace NTwain
{
public class CapabilitiesExt : Capabilities
{
private IDataSource _source;
public CapabilitiesExt(IDataSource dataSource) : base(dataSource) { _source = dataSource; }
private List<CapabilityId> _custom;
public List<CapabilityId> CustomCapabilities
{
get
{
return _custom ?? LoadCustomCapabilities();
}
}
private List<CapabilityId> LoadCustomCapabilities()
{
List<CapabilityId> custom = new List<CapabilityId>();
foreach (CapabilityId capId in CapSupportedCaps.GetValues())
{
var capName = capId.ToString();
var wrapper = GetType().GetProperty(capName);
// not defined in Capabilites
if (wrapper == null)
{
custom.Add(capId);
}
}
return custom;
}
private Func<BoolType, TWOneValue> boolFunc = value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
};
private Func<int, TWOneValue> intFunc = value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
};
private Func<byte, TWOneValue> byteFunc = value => new TWOneValue
{
Item = value,
ItemType = ItemType.UInt8
};
private Func<uint, TWOneValue> uintFunc = value => new TWOneValue
{
Item = value,
ItemType = ItemType.UInt32
};
public object GetCap<TValue> (CapabilityId Capability)
{
QuerySupports? s = QuerySupport(Capability);
bool readOnly = true;
byte b = 0;
if (s != null)
{
b = (byte)s;
if ((b & (1 << 2)) != 0)
{
readOnly = false;
}
}
if (typeof(TValue) == typeof(string))
{
return new CapWrapper<string>(_source, Capability, ValueExtensions.ConvertToString, readOnly);
}
else if (typeof(TValue) == typeof(int))
{
if (readOnly)
{
return new CapWrapper<int>(_source, Capability, ValueExtensions.ConvertToEnum<int>, true);
}
return new CapWrapper<int>(_source, Capability, ValueExtensions.ConvertToEnum<int>, intFunc);
}
else if (typeof(TValue) == typeof(byte))
{
if (readOnly)
{
return new CapWrapper<byte>(_source, Capability, ValueExtensions.ConvertToEnum<byte>, true);
}
return new CapWrapper<byte>(_source, Capability, ValueExtensions.ConvertToEnum<byte>, byteFunc);
}
else if (typeof(TValue) == typeof(uint))
{
if (readOnly)
{
return new CapWrapper<uint>(_source, Capability, ValueExtensions.ConvertToEnum<uint>, true);
}
return new CapWrapper<uint>(_source, Capability, ValueExtensions.ConvertToEnum<uint>, uintFunc);
}
else if (typeof(TValue) == typeof(TWFrame))
{
return new CapWrapper<TWFrame>(_source, Capability, ValueExtensions.ConvertToFrame, readOnly);
}
else if (typeof(TValue) == typeof(BoolType))
{
if (readOnly)
{
return new CapWrapper<BoolType>(_source, Capability, ValueExtensions.ConvertToEnum<BoolType>, true);
}
return new CapWrapper<BoolType>(_source, Capability, ValueExtensions.ConvertToEnum<BoolType>, boolFunc);
}
else if (typeof(TValue) == typeof(TWFix32))
{
if (readOnly)
{
return new CapWrapper<TWFix32>(_source, Capability, ValueExtensions.ConvertToFix32, true);
}
return new CapWrapper<TWFix32>(_source, Capability, ValueExtensions.ConvertToFix32, value => value.ToOneValue());
}
else
{
throw new Exception($"Unknown defintion for type of {typeof(TValue)} in GetCap");
}
}
}
}

View File

@ -443,8 +443,8 @@ namespace NTwain.Data
[StructLayout(LayoutKind.Sequential, Pack = 2)]
partial class TWStatus
{
TW_UINT16 _conditionCode;
TW_UINT16 _data;
internal TW_UINT16 _conditionCode;
internal TW_UINT16 _data;
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]

View File

@ -2301,6 +2301,11 @@ namespace NTwain.Data
public TWStatus Status
{
get { return new TWStatus(_conditionCode, _data); }
internal set
{
_conditionCode = value._conditionCode;
_data = value._data;
}
}
/// <summary>

View File

@ -1103,7 +1103,7 @@ namespace NTwain.Data
IsoB5 = 29,
IsoB7 = 30,
IsoB8 = 31,
IsoB9 = 31,
IsoB9 = 32,
IsoB10 = 33,
JisB0 = 34,
JisB1 = 35,

View File

@ -88,13 +88,14 @@ namespace NTwain
return stat;
}
/// <summary>
/// Gets the source status. Only call this at state 4 or higher.
/// Gets the source status string. Only call this at state 4 or higher.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
public TWStatusUtf8 GetStatusUtf8()
public TWStatusUtf8 GetStatusUtf8(TWStatus status)
{
TWStatusUtf8 stat;
_session.DGControl.StatusUtf8.GetSource(out stat);
_session.DGControl.StatusUtf8.GetSource(status, out stat);
return stat;
}
@ -178,30 +179,27 @@ namespace NTwain
get
{
byte[] value = null;
if (Capabilities.CapCustomDSData.GetCurrent() == BoolType.True)
TWCustomDSData data;
if (DGControl.CustomDSData.Get(out data) == ReturnCode.Success && data.InfoLength > 0)
{
TWCustomDSData data;
if (DGControl.CustomDSData.Get(out data) == ReturnCode.Success && data.InfoLength > 0)
try
{
try
{
value = new byte[data.InfoLength];
var ptr = PlatformInfo.Current.MemoryManager.Lock(data.hData);
Marshal.Copy(ptr, value, 0, (int)data.InfoLength);
}
finally
{
PlatformInfo.Current.MemoryManager.Unlock(data.hData);
PlatformInfo.Current.MemoryManager.Free(data.hData);
}
value = new byte[data.InfoLength];
var ptr = PlatformInfo.Current.MemoryManager.Lock(data.hData);
Marshal.Copy(ptr, value, 0, (int)data.InfoLength);
}
finally
{
PlatformInfo.Current.MemoryManager.Unlock(data.hData);
PlatformInfo.Current.MemoryManager.Free(data.hData);
}
}
return value;
}
set
{
if (value != null && value.Length > 0 &&
Capabilities.CapCustomDSData.GetCurrent() == BoolType.True)
if (value != null && value.Length > 0)
{
TWCustomDSData data = new TWCustomDSData
{
@ -257,7 +255,7 @@ namespace NTwain
// }
//}
private Capabilities _caps;
private CapabilitiesExt _caps;
/// <summary>
/// Gets the capabilities for this data source.
@ -267,7 +265,7 @@ namespace NTwain
/// </value>
public ICapabilities Capabilities
{
get { return _caps ?? (_caps = new Capabilities(this)); }
get { return _caps ?? (_caps = new CapabilitiesExt(this)); }
}

Binary file not shown.

View File

@ -116,9 +116,10 @@ namespace NTwain
TWStatus GetStatus();
/// <summary>
/// Gets the source status. Only call this at state 4 or higher.
/// Gets the source status string. Only call this at state 4 or higher.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
TWStatusUtf8 GetStatusUtf8();
TWStatusUtf8 GetStatusUtf8(TWStatus status);
}
}

View File

@ -168,10 +168,11 @@ namespace NTwain
TWStatus GetStatus();
/// <summary>
/// Gets the manager status. Only call this at state 3 or higher.
/// Gets the manager status string. Only call this at state 3 or higher.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
TWStatusUtf8 GetStatusUtf8();
TWStatusUtf8 GetStatusUtf8(TWStatus status);
/// <summary>

View File

@ -41,6 +41,7 @@ namespace NTwain.Internals
ReturnCode DisableSource();
void SafeSyncableRaiseEvent(DataTransferredEventArgs e);
void SafeSyncableRaiseEvent(TransferCanceledEventArgs e);
void SafeSyncableRaiseEvent(TransferErrorEventArgs e);
void SafeSyncableRaiseEvent(TransferReadyEventArgs e);

View File

@ -145,9 +145,11 @@ namespace NTwain.Internals
{
case ReturnCode.Success:
case ReturnCode.XferDone:
case ReturnCode.Cancel:
// ok to keep going
break;
case ReturnCode.Cancel:
session.SafeSyncableRaiseEvent(new TransferCanceledEventArgs());
break;
default:
var status = session.CurrentSource.GetStatus();
session.SafeSyncableRaiseEvent(new TransferErrorEventArgs(rc, status));

View File

@ -1,184 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0C5A6FB1-0282-4D61-8354-68DEB1515001}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NTwain</RootNamespace>
<AssemblyName>NTwain</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<PackageId>NTwain</PackageId>
<Description>Library containing the TWAIN API for dotnet.</Description>
<TargetFrameworks>net5.0-windows;net6.0-windows;net462;net40</TargetFrameworks>
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
<PackageTags>twain scan</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIconUrl>https://github.com/soukoku/ntwain/blob/master/Scanner-Icon.png?raw=true</PackageIconUrl>
<RepositoryUrl>https://github.com/soukoku/ntwain</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<NeutralLanguage>en-US</NeutralLanguage>
<!--<Copyright>Eugene Wang 2012</Copyright>-->
<Authors>Eugene Wang</Authors>
<!--<SignAssembly>true</SignAssembly>-->
<!--<AssemblyOriginatorKeyFile>Sign.snk</AssemblyOriginatorKeyFile>-->
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.7.5</FileVersion>
<Version>3.7.5</Version>
<LangVersion>7.1</LangVersion>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\release-build\strong-name.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET4</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<DocumentationFile>
</DocumentationFile>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NET4</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\NTwain.xml</DocumentationFile>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Sign.snk</AssemblyOriginatorKeyFile>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
<!--<ItemGroup Condition="'$(TargetFramework)' == 'net35'">
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>-->
<ItemGroup>
<Compile Include="CapWrapper.cs" />
<Compile Include="CapabilityReader.cs" />
<Compile Include="Data\TypeExtensions.cs" />
<Compile Include="Data\TwainTypesExtended.cs" />
<Compile Include="DeviceEventArgs.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ICapabilities.cs" />
<Compile Include="IDataSource.cs" />
<Compile Include="ILog.cs" />
<Compile Include="Internals\TraceLog.cs" />
<Compile Include="Internals\Extensions.cs" />
<Compile Include="DataTransferredEventArgs.cs" />
<Compile Include="IMemoryManager.cs" />
<Compile Include="Internals\ICommittable.cs" />
<Compile Include="Internals\ImageTools.cs" />
<Compile Include="Internals\InternalMessageLoopHook.cs" />
<Compile Include="Internals\ITwainSessionInternal.cs" />
<Compile Include="Internals\LinuxMemoryManager.cs" />
<Compile Include="Interop\BITMAP.cs" />
<Compile Include="Interop\MESSAGE.cs" />
<Compile Include="Internals\TransferLogic.cs" />
<Compile Include="Internals\WindowsHook.cs" />
<Compile Include="Internals\WrappedManualResetEvent.cs" />
<Compile Include="Interop\NativeMethods.cs" />
<Compile Include="Interop\TIFF.cs" />
<Compile Include="IPlatformInfo.cs" />
<Compile Include="ITripletControl.cs" />
<Compile Include="ITwainSession.cs" />
<Compile Include="Internals\WinMemoryManager.cs" />
<Compile Include="Interop\UnsafeNativeMethods.cs" />
<Compile Include="Internals\IWinMessageFilter.cs" />
<Compile Include="ICapWrapper.cs" />
<Compile Include="MessageLoopHooks.cs" />
<Compile Include="PlatformInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\VersionInfo.cs" />
<Compile Include="Internals\TentativeStateCommitable.cs" />
<Compile Include="ProtocolVersions.cs" />
<Compile Include="State.cs" />
<Compile Include="TransferErrorEventArgs.cs" />
<Compile Include="TransferReadyEventArgs.cs" />
<Compile Include="Triplets\DGControl\DGControl.Callback2.cs" />
<Compile Include="Triplets\DGControl\DGControl.CapabilityCustom.cs" />
<Compile Include="Triplets\DGImage\DGImage.Filter.cs" />
<Compile Include="Triplets\DGCustom.cs" />
<Compile Include="Triplets\TripletBase.cs" />
<Compile Include="Triplets\Dsm.Linux.cs" />
<Compile Include="Triplets\Dsm.WinOld.cs" />
<Compile Include="Triplets\Dsm.WinNew.cs" />
<Compile Include="TwainSessionInternal.cs" />
<Compile Include="Capabilities.cs" />
<Compile Include="TwainSession.cs" />
<Compile Include="DataSource.cs" />
<Compile Include="TwainStateException.cs" />
<Compile Include="Data\TwainTypes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Triplets\DGAudio\DGAudio.AudioFileXfer.cs" />
<Compile Include="Triplets\DGAudio\DGAudio.AudioInfo.cs" />
<Compile Include="Triplets\DGAudio\DGAudio.AudioNativeXfer.cs" />
<Compile Include="Triplets\DGAudio\DGAudio.cs" />
<Compile Include="Triplets\DGControl\DGControl.Callback.cs" />
<Compile Include="Triplets\DGControl\DGControl.Capability.cs" />
<Compile Include="Triplets\DGControl\DGControl.cs" />
<Compile Include="Triplets\DGControl\DGControl.CustomDSData.cs" />
<Compile Include="Triplets\DGControl\DGControl.DeviceEvent.cs" />
<Compile Include="Triplets\DGControl\DGControl.EntryPoint.cs" />
<Compile Include="Triplets\DGControl\DGControl.Event.cs" />
<Compile Include="Triplets\DGControl\DGControl.FileSystem.cs" />
<Compile Include="Triplets\DGControl\DGControl.Identity.cs" />
<Compile Include="Triplets\DGControl\DGControl.Parent.cs" />
<Compile Include="Triplets\DGControl\DGControl.PassThru.cs" />
<Compile Include="Triplets\DGControl\DGControl.PendingXfers.cs" />
<Compile Include="Triplets\DGControl\DGControl.SetupFileXfer.cs" />
<Compile Include="Triplets\DGControl\DGControl.SetupMemXfer.cs" />
<Compile Include="Triplets\DGControl\DGControl.Status.cs" />
<Compile Include="Triplets\DGControl\DGControl.StatusUtf8.cs" />
<Compile Include="Triplets\DGControl\DGControl.UserInterface.cs" />
<Compile Include="Triplets\DGControl\DGControl.XferGroup.cs" />
<Compile Include="Triplets\DGImage\DGImage.CieColor.cs" />
<Compile Include="Triplets\DGImage\DGImage.cs" />
<Compile Include="Triplets\DGImage\DGImage.ExtImageInfo.cs" />
<Compile Include="Triplets\DGImage\DGImage.GrayResponse.cs" />
<Compile Include="Triplets\DGImage\DGImage.IccProfile.cs" />
<Compile Include="Triplets\DGImage\DGImage.ImageFileXfer.cs" />
<Compile Include="Triplets\DGImage\DGImage.ImageInfo.cs" />
<Compile Include="Triplets\DGImage\DGImage.ImageLayout.cs" />
<Compile Include="Triplets\DGImage\DGImage.ImageMemFileXfer.cs" />
<Compile Include="Triplets\DGImage\DGImage.ImageMemXfer.cs" />
<Compile Include="Triplets\DGImage\DGImage.ImageNativeXfer.cs" />
<Compile Include="Triplets\DGImage\DGImage.JpegCompression.cs" />
<Compile Include="Triplets\DGImage\DGImage.Palette8.cs" />
<Compile Include="Triplets\DGImage\DGImage.RgbResponse.cs" />
<Compile Include="Triplets\Dsm.cs" />
<Compile Include="TwainException.cs" />
<Compile Include="Data\TwainValues.cs" />
<Compile Include="SourceEnableMode.cs" />
<Compile Include="Data\ValueExtensions.cs" />
<Compile Include="WpfImageTools.cs" />
</ItemGroup>
<ItemGroup>
<None Include="NTwain.nuspec" />
</ItemGroup>
<ItemGroup>
<None Include="Sign.snk" />
<None Include="Triplets\WhatsThis.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>https://bitbucket.org/soukoku/ntwain/src/15de55c6314f14ab2b1cb22f64397d9487c783d0/LICENSE.txt?at=master</licenseUrl>
<projectUrl>https://bitbucket.org/soukoku/ntwain</projectUrl>
<iconUrl>https://bytebucket.org/soukoku/ntwain/raw/6927ac18780cebbfa33ee7bc4864b9a6777c5fb6/Scanner-Icon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>This release supports TWAIN 2.3.</releaseNotes>
<copyright>$copyright$</copyright>
<tags>twain scan</tags>
</metadata>
<files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net40-client"/>
<file src="bin\$configuration$\Net35\$id$.dll" target="lib\net35-client"/>
<file src="bin\$configuration$\Net35\$id$.xml" target="lib\net35-client"/>
<file src="bin\$configuration$\Net35\$id$.pdb" target="lib\net35-client"/>
</files>
</package>

View File

@ -4,15 +4,10 @@ using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("NTwain")]
[assembly: AssemblyDescription("Library containing the TWAIN API for dotnet.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("NTwain")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: NeutralResourcesLanguage("en", UltimateResourceFallbackLocation.MainAssembly)]
#if DEBUG
[assembly: InternalsVisibleTo(@"NTwain.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100ad02a9cc0f8ee929ad066a59951057ba3b9f400ff5c176988935ea72d9738003df98d65ccde2c8eecd75fa0414e7816d7475d379ef9b93601ff4d2a8807d61398a19405e0f6a79c7c523fd02c93c2bfaf9b818f43a88542ba22df80811d24260be737d6e303e91aadf4588b23c809494d164728462d6f1292928c8fab7ea06c5")]

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -19,7 +19,7 @@ namespace NTwain.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {

View File

@ -1,30 +0,0 @@
using System.Reflection;
[assembly: AssemblyCopyright("Copyright \x00a9 Yin-Chun Wang 2012-2018")]
[assembly: AssemblyCompany("Yin-Chun Wang")]
[assembly: AssemblyVersion(NTwain.VersionInfo.Release)]
[assembly: AssemblyFileVersion(NTwain.VersionInfo.Build)]
[assembly: AssemblyInformationalVersion(NTwain.VersionInfo.Build)]
namespace NTwain
{
/// <summary>
/// Contains version info of NTwain.
/// </summary>
static class VersionInfo
{
/// <summary>
/// The major release version number.
/// </summary>
public const string Release = "3.0.0.0"; // keep this same in major (breaking) releases
/// <summary>
/// The build release version number.
/// </summary>
public const string Build = "3.5.3"; // change this for each nuget release
}
}

View File

@ -0,0 +1,17 @@
using System;
namespace NTwain
{
/// <summary>
/// Indicates a transfer cancellation, e.g. if the user pressed the "Cancel" button.
/// </summary>
public class TransferCanceledEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="TransferCanceledEventArgs"/> class.
/// </summary>
public TransferCanceledEventArgs()
{
}
}
}

View File

@ -19,7 +19,8 @@ namespace NTwain.Triplets
{
Session.VerifyState(6, 6, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get);
IntPtr z = IntPtr.Zero;
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get, ref z);
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity,
DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get, ref z);
}
}
}

View File

@ -22,7 +22,8 @@ namespace NTwain.Triplets
public ReturnCode Get(ref IntPtr handle)
{
Session.VerifyState(6, 6, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get);
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get, ref handle);
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity,
DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get, ref handle);
}
}
}

View File

@ -16,9 +16,9 @@ namespace NTwain.Triplets
/// </summary>
/// <param name="status">The status.</param>
/// <returns></returns>
public ReturnCode GetManager(out TWStatusUtf8 status)
public ReturnCode GetManager(TWStatus status, out TWStatusUtf8 utf8status)
{
status = new TWStatusUtf8();
utf8status = new TWStatusUtf8 { Status = status };
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get);
return Dsm.DsmEntry(Session.AppId, null, Message.Get, status);
}
@ -29,9 +29,9 @@ namespace NTwain.Triplets
/// </summary>
/// <param name="status">The status.</param>
/// <returns></returns>
public ReturnCode GetSource(out TWStatusUtf8 status)
public ReturnCode GetSource(TWStatus status, out TWStatusUtf8 utf8status)
{
status = new TWStatusUtf8();
utf8status = new TWStatusUtf8 { Status = status };
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get);
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, status);
}

View File

@ -39,6 +39,24 @@ namespace NTwain.Triplets
return Dsm.DsmEntry(_session.AppId, _session.CurrentSource.Identity, group, dat, message, ref data);
}
/// <summary>
/// Direct DSM_Entry call with full arguments for custom values.
/// </summary>
/// <param name="group">The group.</param>
/// <param name="dat">The dat.</param>
/// <param name="message">The message.</param>
/// <param name="data">The data.</param>
/// <returns></returns>
public ReturnCode DsmEntry(
DataGroups group,
DataArgumentType dat,
Message message,
IntPtr data)
{
_session.VerifyState(3, 7, group, dat, message);
return Dsm.DsmEntry(_session.AppId, _session.CurrentSource.Identity, group, dat, message, data);
}
// todo: add other data value types?
}
}

View File

@ -18,6 +18,15 @@ namespace NTwain.Triplets
Message msg,
ref IntPtr data);
[DllImport(LINUX_DSM_PATH, EntryPoint = DSM_ENTRY)]
public static extern ReturnCode DsmLinux(
[In, Out]TWIdentity origin,
[In, Out]TWIdentity destination,
DataGroups dg,
DataArgumentType dat,
Message msg,
IntPtr data);
[DllImport(LINUX_DSM_PATH, EntryPoint = DSM_ENTRY)]
public static extern ReturnCode DsmLinux(
[In, Out]TWIdentity origin,

View File

@ -17,6 +17,15 @@ namespace NTwain.Triplets
Message msg,
ref IntPtr data);
[DllImport(WIN_NEW_DSM_NAME, EntryPoint = DSM_ENTRY)]
public static extern ReturnCode DsmWinNew(
[In, Out]TWIdentity origin,
[In, Out]TWIdentity destination,
DataGroups dg,
DataArgumentType dat,
Message msg,
IntPtr data);
[DllImport(WIN_NEW_DSM_NAME, EntryPoint = DSM_ENTRY)]
public static extern ReturnCode DsmWinNew(
[In, Out]TWIdentity origin,

View File

@ -17,6 +17,15 @@ namespace NTwain.Triplets
Message msg,
ref IntPtr data);
[DllImport(WIN_OLD_DSM_NAME, EntryPoint = DSM_ENTRY)]
public static extern ReturnCode DsmWinOld(
[In, Out]TWIdentity origin,
[In, Out]TWIdentity destination,
DataGroups dg,
DataArgumentType dat,
Message msg,
IntPtr data);
[DllImport(WIN_OLD_DSM_NAME, EntryPoint = DSM_ENTRY)]
public static extern ReturnCode DsmWinOld(
[In, Out]TWIdentity origin,

View File

@ -37,6 +37,26 @@ namespace NTwain.Triplets
throw new PlatformNotSupportedException();
}
public static ReturnCode DsmEntry(
TWIdentity origin,
TWIdentity destination,
DataGroups dg,
DataArgumentType dat,
Message msg,
IntPtr data)
{
if (PlatformInfo.Current.IsWindows)
{
if (PlatformInfo.Current.UseNewWinDSM) { return NativeMethods.DsmWinNew(origin, destination, dg, dat, msg, data); }
else { return NativeMethods.DsmWinOld(origin, destination, dg, dat, msg, data); }
}
else if (PlatformInfo.Current.IsLinux)
{
return NativeMethods.DsmLinux(origin, destination, dg, dat, msg, data);
}
throw new PlatformNotSupportedException();
}
public static ReturnCode DsmEntry(
TWIdentity origin,
TWIdentity destination,
@ -161,12 +181,12 @@ namespace NTwain.Triplets
{
if (PlatformInfo.Current.IsWindows)
{
if (PlatformInfo.Current.UseNewWinDSM) { return NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
else { return NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
if (PlatformInfo.Current.UseNewWinDSM) { return NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, DataArgumentType.Callback2, msg, data); }
else { return NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, DataArgumentType.Callback2, msg, data); }
}
else if (PlatformInfo.Current.IsLinux)
{
return NativeMethods.DsmLinux(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data);
return NativeMethods.DsmLinux(origin, destination, DataGroups.Control, DataArgumentType.Callback2, msg, data);
}
throw new PlatformNotSupportedException();
}

View File

@ -78,6 +78,17 @@ namespace NTwain
#region ITwainSession Members
DGCustom _dgCustom;
DGCustom ITripletControl.DGCustom { get { return DGCustom; } }
public DGCustom DGCustom
{
get
{
if (_dgCustom == null) { _dgCustom = new DGCustom(this); }
return _dgCustom;
}
}
/// <summary>
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
/// </summary>
@ -362,13 +373,14 @@ namespace NTwain
}
/// <summary>
/// Gets the manager status. Only call this at state 3 or higher.
/// Gets the manager status string. Only call this at state 3 or higher.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
public TWStatusUtf8 GetStatusUtf8()
public TWStatusUtf8 GetStatusUtf8(TWStatus status)
{
TWStatusUtf8 stat;
((ITwainSessionInternal)this).DGControl.StatusUtf8.GetManager(out stat);
((ITwainSessionInternal)this).DGControl.StatusUtf8.GetManager(status, out stat);
return stat;
}
@ -470,6 +482,10 @@ namespace NTwain
/// </summary>
public event EventHandler<DataTransferredEventArgs> DataTransferred;
/// <summary>
/// Occurs when a transfer was canceled.
/// </summary>
public event EventHandler<TransferCanceledEventArgs> TransferCanceled;
/// <summary>
/// Occurs when an error has been encountered during transfer.
/// </summary>
public event EventHandler<TransferErrorEventArgs> TransferError;
@ -668,6 +684,12 @@ namespace NTwain
/// <param name="e">The <see cref="DataTransferredEventArgs"/> instance containing the event data.</param>
protected virtual void OnDataTransferred(DataTransferredEventArgs e) { }
/// <summary>
/// Called when a transfer was canceled.
/// </summary>
/// <param name="e">The <see cref="TransferCanceledEventArgs"/> instance containing the event data.</param>
protected virtual void OnTransferCanceled(TransferCanceledEventArgs e) { }
/// <summary>
/// Called when an error has been encountered during transfer.
/// </summary>

View File

@ -96,6 +96,10 @@ namespace NTwain
{
SafeSyncableRaiseOnEvent(OnDataTransferred, DataTransferred, e);
}
void ITwainSessionInternal.SafeSyncableRaiseEvent(TransferCanceledEventArgs e)
{
SafeSyncableRaiseOnEvent(OnTransferCanceled, TransferCanceled, e);
}
void ITwainSessionInternal.SafeSyncableRaiseEvent(TransferErrorEventArgs e)
{
SafeSyncableRaiseOnEvent(OnTransferError, TransferError, e);
@ -138,17 +142,6 @@ namespace NTwain
}
}
DGCustom _dgCustom;
DGCustom ITripletControl.DGCustom { get { return DGCustom; } }
protected DGCustom DGCustom
{
get
{
if (_dgCustom == null) { _dgCustom = new DGCustom(this); }
return _dgCustom;
}
}
/// <summary>
/// Enables the source to start transferring.