mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Moved to src folder and put Windows things in own proj.
This commit is contained in:
parent
46414c74a6
commit
8fe54398b9
12
NTwain.sln
12
NTwain.sln
@ -5,19 +5,21 @@ VisualStudioVersion = 16.0.31205.134
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
src\Directory.Build.props = src\Directory.Build.props
|
||||
LICENSE.txt = LICENSE.txt
|
||||
size-test\main.cpp = size-test\main.cpp
|
||||
README.md = README.md
|
||||
twain-doc\TWAIN-2.4-Specification.pdf = twain-doc\TWAIN-2.4-Specification.pdf
|
||||
twain-doc\twain2.4.h = twain-doc\twain2.4.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain", "NTwain\NTwain.csproj", "{B391C1B7-5647-4B7A-9079-81E835E633DD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NTwain", "src\NTwain\NTwain.csproj", "{B391C1B7-5647-4B7A-9079-81E835E633DD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net5Console", "samples\Net5Console\Net5Console.csproj", "{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Net5Console", "samples\Net5Console\Net5Console.csproj", "{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{707B4313-8EF8-4D0F-A95E-590783422187}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NTwain.Win", "src\NTwain.Win\NTwain.Win.csproj", "{F836149E-E64D-476E-A325-478D18BE1CC7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -32,6 +34,10 @@ Global
|
||||
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F836149E-E64D-476E-A325-478D18BE1CC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F836149E-E64D-476E-A325-478D18BE1CC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F836149E-E64D-476E-A325-478D18BE1CC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F836149E-E64D-476E-A325-478D18BE1CC7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,104 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows work to be marshalled to a different (usually UI) thread if necessary.
|
||||
/// </summary>
|
||||
public interface IThreadMarshaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts work asynchronously and returns immediately.
|
||||
/// </summary>
|
||||
/// <param name="work"></param>
|
||||
void BeginInvoke(Delegate work, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Starts work synchronously until it returns.
|
||||
/// </summary>
|
||||
/// <param name="work"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
object Invoke(Delegate work, params object[] args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Doesn't actually use any particular thread.
|
||||
/// Should only be used in non-UI apps.
|
||||
/// </summary>
|
||||
public class NoParticularMarshaller : IThreadMarshaller
|
||||
{
|
||||
public bool InvokeRequired => throw new NotImplementedException();
|
||||
|
||||
public void BeginInvoke(Delegate work, params object[] args)
|
||||
{
|
||||
Task.Run(() => work.DynamicInvoke(args));
|
||||
}
|
||||
|
||||
public object Invoke(Delegate work, params object[] args)
|
||||
{
|
||||
return work.DynamicInvoke(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Uses a winform UI thread to do the work.
|
||||
/// </summary>
|
||||
public class WinformMarshaller : IThreadMarshaller
|
||||
{
|
||||
private readonly System.Windows.Forms.Control _uiControl;
|
||||
|
||||
/// <summary>
|
||||
/// Uses a control whose UI thread is used to run the work.
|
||||
/// </summary>
|
||||
/// <param name="uiControl"></param>
|
||||
public WinformMarshaller(System.Windows.Forms.Control uiControl)
|
||||
{
|
||||
_uiControl = uiControl ?? throw new ArgumentNullException(nameof(uiControl));
|
||||
}
|
||||
|
||||
public void BeginInvoke(Delegate work, params object[] args)
|
||||
{
|
||||
_uiControl.BeginInvoke(work, args);
|
||||
}
|
||||
|
||||
public object Invoke(Delegate work, params object[] args)
|
||||
{
|
||||
return _uiControl.Invoke(work, args);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses a WPF dispatcher to do the work.
|
||||
/// </summary>
|
||||
public class DispatcherMarshaller : IThreadMarshaller
|
||||
{
|
||||
private readonly System.Windows.Threading.Dispatcher _dispatcher;
|
||||
|
||||
/// <summary>
|
||||
/// Uses a dispatcher whose UI thread is used to run the work.
|
||||
/// </summary>
|
||||
/// <param name="dispatcher"></param>
|
||||
public DispatcherMarshaller(System.Windows.Threading.Dispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
|
||||
}
|
||||
|
||||
public void BeginInvoke(Delegate work, params object[] args)
|
||||
{
|
||||
_dispatcher.BeginInvoke(work, args);
|
||||
}
|
||||
|
||||
public object Invoke(Delegate work, params object[] args)
|
||||
{
|
||||
return _dispatcher.Invoke(work, args);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,12 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\NTwain\NTwain.csproj" />
|
||||
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,10 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Project ToolsVersion="15.0">
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain</PackageId>
|
||||
<Version>4.0.0</Version>
|
||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
||||
<TargetFrameworks>net45;netcoreapp3.1;net5.0-windows</TargetFrameworks>
|
||||
<!--change in each release-->
|
||||
<PackageVersion>4.0.0</PackageVersion>
|
||||
|
||||
<!--keep major the same until it changes-->
|
||||
<AssemblyVersion>4.0.0.0</AssemblyVersion>
|
||||
|
||||
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
|
||||
<PackageTags>twain scan</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
@ -14,11 +15,12 @@
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<!--<Copyright>Eugene Wang 2012</Copyright>-->
|
||||
<Authors>Eugene Wang</Authors>
|
||||
<AssemblyVersion>4.0.0.0</AssemblyVersion>
|
||||
<FileVersion>4.0.0.0</FileVersion>
|
||||
|
||||
<Version>$(PkgVersion)</Version>
|
||||
<FileVersion>$(PkgVersion)</FileVersion>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UseWPF>true</UseWPF>
|
||||
<!--don't warn missing xml docs-->
|
||||
<NoWarn>1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
@ -31,28 +33,5 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="System.Drawing.Common">
|
||||
<Version>5.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Security.Permissions">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>-->
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
|
||||
<PackageReference Include="System.Text.Encoding.CodePages">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
|
||||
<PackageReference Include="System.Text.Encoding.CodePages">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
31
src/NTwain.Win/DispatcherMarshaller.cs
Normal file
31
src/NTwain.Win/DispatcherMarshaller.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Uses a WPF dispatcher to do the work.
|
||||
/// </summary>
|
||||
public class DispatcherMarshaller : IThreadMarshaller
|
||||
{
|
||||
private readonly System.Windows.Threading.Dispatcher _dispatcher;
|
||||
|
||||
/// <summary>
|
||||
/// Uses a dispatcher whose UI thread is used to run the work.
|
||||
/// </summary>
|
||||
/// <param name="dispatcher"></param>
|
||||
public DispatcherMarshaller(System.Windows.Threading.Dispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
|
||||
}
|
||||
|
||||
public void BeginInvoke(Delegate work, params object[] args)
|
||||
{
|
||||
_dispatcher.BeginInvoke(work, args);
|
||||
}
|
||||
|
||||
public object Invoke(Delegate work, params object[] args)
|
||||
{
|
||||
return _dispatcher.Invoke(work, args);
|
||||
}
|
||||
}
|
||||
}
|
16
src/NTwain.Win/NTwain.Win.csproj
Normal file
16
src/NTwain.Win/NTwain.Win.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain.Win</PackageId>
|
||||
<Description>Contains Windows specific things for NTwain.</Description>
|
||||
<TargetFrameworks>net45;netcoreapp3.1;net5.0-windows</TargetFrameworks>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<UseWPF>true</UseWPF>
|
||||
<RootNamespace>NTwain</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NTwain\NTwain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
31
src/NTwain.Win/WinformMarshaller.cs
Normal file
31
src/NTwain.Win/WinformMarshaller.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Uses a winform UI thread to do the work.
|
||||
/// </summary>
|
||||
public class WinformMarshaller : IThreadMarshaller
|
||||
{
|
||||
private readonly System.Windows.Forms.Control _uiControl;
|
||||
|
||||
/// <summary>
|
||||
/// Uses a control whose UI thread is used to run the work.
|
||||
/// </summary>
|
||||
/// <param name="uiControl"></param>
|
||||
public WinformMarshaller(System.Windows.Forms.Control uiControl)
|
||||
{
|
||||
_uiControl = uiControl ?? throw new ArgumentNullException(nameof(uiControl));
|
||||
}
|
||||
|
||||
public void BeginInvoke(Delegate work, params object[] args)
|
||||
{
|
||||
_uiControl.BeginInvoke(work, args);
|
||||
}
|
||||
|
||||
public object Invoke(Delegate work, params object[] args)
|
||||
{
|
||||
return _uiControl.Invoke(work, args);
|
||||
}
|
||||
}
|
||||
}
|
34
src/NTwain/NTwain.csproj
Normal file
34
src/NTwain/NTwain.csproj
Normal file
@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain</PackageId>
|
||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
||||
<TargetFrameworks>net45;netcoreapp3.1;net5.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="System.Drawing.Common">
|
||||
<Version>5.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Security.Permissions">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>-->
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
|
||||
<PackageReference Include="System.Text.Encoding.CodePages">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
<PackageReference Include="System.Text.Encoding.CodePages">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
File diff suppressed because it is too large
Load Diff
49
src/NTwain/ThreadMarshaller.cs
Normal file
49
src/NTwain/ThreadMarshaller.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows work to be marshalled to a different (usually UI) thread if necessary.
|
||||
/// </summary>
|
||||
public interface IThreadMarshaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts work asynchronously and returns immediately.
|
||||
/// </summary>
|
||||
/// <param name="work"></param>
|
||||
void BeginInvoke(Delegate work, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Starts work synchronously until it returns.
|
||||
/// </summary>
|
||||
/// <param name="work"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
object Invoke(Delegate work, params object[] args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Doesn't actually use any particular thread.
|
||||
/// Should only be used in non-UI apps.
|
||||
/// </summary>
|
||||
public class NoParticularMarshaller : IThreadMarshaller
|
||||
{
|
||||
public bool InvokeRequired => throw new NotImplementedException();
|
||||
|
||||
public void BeginInvoke(Delegate work, params object[] args)
|
||||
{
|
||||
Task.Run(() => work.DynamicInvoke(args));
|
||||
}
|
||||
|
||||
public object Invoke(Delegate work, params object[] args)
|
||||
{
|
||||
return work.DynamicInvoke(args);
|
||||
}
|
||||
}
|
||||
}
|
BIN
twain-doc/TWAIN_Errata_for_Version_2.4.pdf
Normal file
BIN
twain-doc/TWAIN_Errata_for_Version_2.4.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user