mirror of
https://github.com/soukoku/ntwain.git
synced 2025-07-15 23:15:53 +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
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
src\Directory.Build.props = src\Directory.Build.props
|
||||||
LICENSE.txt = LICENSE.txt
|
LICENSE.txt = LICENSE.txt
|
||||||
size-test\main.cpp = size-test\main.cpp
|
|
||||||
README.md = README.md
|
README.md = README.md
|
||||||
twain-doc\TWAIN-2.4-Specification.pdf = twain-doc\TWAIN-2.4-Specification.pdf
|
twain-doc\TWAIN-2.4-Specification.pdf = twain-doc\TWAIN-2.4-Specification.pdf
|
||||||
twain-doc\twain2.4.h = twain-doc\twain2.4.h
|
twain-doc\twain2.4.h = twain-doc\twain2.4.h
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
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
|
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
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{707B4313-8EF8-4D0F-A95E-590783422187}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{707B4313-8EF8-4D0F-A95E-590783422187}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NTwain.Win", "src\NTwain.Win\NTwain.Win.csproj", "{F836149E-E64D-476E-A325-478D18BE1CC7}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
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>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0-windows</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\NTwain\NTwain.csproj" />
|
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project ToolsVersion="15.0">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackageId>NTwain</PackageId>
|
<!--change in each release-->
|
||||||
<Version>4.0.0</Version>
|
<PackageVersion>4.0.0</PackageVersion>
|
||||||
<Description>Library containing the TWAIN API for dotnet.</Description>
|
|
||||||
<TargetFrameworks>net45;netcoreapp3.1;net5.0-windows</TargetFrameworks>
|
<!--keep major the same until it changes-->
|
||||||
|
<AssemblyVersion>4.0.0.0</AssemblyVersion>
|
||||||
|
|
||||||
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
|
||||||
<PackageTags>twain scan</PackageTags>
|
<PackageTags>twain scan</PackageTags>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
@ -14,11 +15,12 @@
|
|||||||
<NeutralLanguage>en-US</NeutralLanguage>
|
<NeutralLanguage>en-US</NeutralLanguage>
|
||||||
<!--<Copyright>Eugene Wang 2012</Copyright>-->
|
<!--<Copyright>Eugene Wang 2012</Copyright>-->
|
||||||
<Authors>Eugene Wang</Authors>
|
<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>
|
<LangVersion>7.1</LangVersion>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<!--don't warn missing xml docs-->
|
||||||
<UseWPF>true</UseWPF>
|
<NoWarn>1591</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||||
@ -31,28 +33,5 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
|
||||||
</ItemGroup>
|
</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>
|
@ -116,7 +116,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_scancallback">Function to handle scanning</param>
|
/// <param name="a_scancallback">Function to handle scanning</param>
|
||||||
/// <param name="a_runinuithreaddelegate">Help us run in the GUI thread on Windows</param>
|
/// <param name="a_runinuithreaddelegate">Help us run in the GUI thread on Windows</param>
|
||||||
/// <param name="a_intptrHwnd">window handle</param>
|
/// <param name="a_intptrHwnd">window handle</param>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public TWAIN
|
public TWAIN
|
||||||
(
|
(
|
||||||
string a_szManufacturer,
|
string a_szManufacturer,
|
||||||
@ -264,7 +263,7 @@ namespace TWAINWorkingGroup
|
|||||||
// we find an old DSM...
|
// we find an old DSM...
|
||||||
foreach (string szDsm in aszDsm)
|
foreach (string szDsm in aszDsm)
|
||||||
{
|
{
|
||||||
if ( szDsm.EndsWith("so.2.0") || szDsm.Contains(".so.2.0.")
|
if (szDsm.EndsWith("so.2.0") || szDsm.Contains(".so.2.0.")
|
||||||
|| szDsm.EndsWith("so.2.1") || szDsm.Contains(".so.2.1.")
|
|| szDsm.EndsWith("so.2.1") || szDsm.Contains(".so.2.1.")
|
||||||
|| szDsm.EndsWith("so.2.2") || szDsm.Contains(".so.2.2.")
|
|| szDsm.EndsWith("so.2.2") || szDsm.Contains(".so.2.2.")
|
||||||
|| szDsm.EndsWith("so.2.3") || szDsm.Contains(".so.2.3."))
|
|| szDsm.EndsWith("so.2.3") || szDsm.Contains(".so.2.3."))
|
||||||
@ -281,7 +280,7 @@ namespace TWAINWorkingGroup
|
|||||||
p.WaitForExit();
|
p.WaitForExit();
|
||||||
p.Dispose();
|
p.Dispose();
|
||||||
// We never did any 1.x stuff...
|
// We never did any 1.x stuff...
|
||||||
if ( (szOutput != null)
|
if ((szOutput != null)
|
||||||
&& (szOutput.EndsWith(".so.2.0") || szOutput.Contains(".so.2.0.")
|
&& (szOutput.EndsWith(".so.2.0") || szOutput.Contains(".so.2.0.")
|
||||||
|| szOutput.EndsWith(".so.2.1") || szOutput.Contains(".so.2.1.")
|
|| szOutput.EndsWith(".so.2.1") || szOutput.Contains(".so.2.1.")
|
||||||
|| szOutput.EndsWith(".so.2.2") || szOutput.Contains(".so.2.2.")
|
|| szOutput.EndsWith(".so.2.2") || szOutput.Contains(".so.2.2.")
|
||||||
@ -301,7 +300,7 @@ namespace TWAINWorkingGroup
|
|||||||
foreach (string szDsm in aszDsm)
|
foreach (string szDsm in aszDsm)
|
||||||
{
|
{
|
||||||
// I guess this is reasonably future-proof...
|
// I guess this is reasonably future-proof...
|
||||||
if ( szDsm.Contains("so.2.4")
|
if (szDsm.Contains("so.2.4")
|
||||||
|| szDsm.Contains("so.2.5")
|
|| szDsm.Contains("so.2.5")
|
||||||
|| szDsm.Contains("so.2.6")
|
|| szDsm.Contains("so.2.6")
|
||||||
|| szDsm.Contains("so.2.7")
|
|| szDsm.Contains("so.2.7")
|
||||||
@ -474,7 +473,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a_u32Size">Number of bytes to allocate</param>
|
/// <param name="a_u32Size">Number of bytes to allocate</param>
|
||||||
/// <returns>Point to memory</returns>
|
/// <returns>Point to memory</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public IntPtr DsmMemAlloc(uint a_u32Size, bool a_blForcePointer = false)
|
public IntPtr DsmMemAlloc(uint a_u32Size, bool a_blForcePointer = false)
|
||||||
{
|
{
|
||||||
IntPtr intptr;
|
IntPtr intptr;
|
||||||
@ -540,7 +538,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// Free memory used with the data source...
|
/// Free memory used with the data source...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a_intptrHandle">Pointer to free</param>
|
/// <param name="a_intptrHandle">Pointer to free</param>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public void DsmMemFree(ref IntPtr a_intptrHandle, bool a_blForcePointer = false)
|
public void DsmMemFree(ref IntPtr a_intptrHandle, bool a_blForcePointer = false)
|
||||||
{
|
{
|
||||||
// Validate...
|
// Validate...
|
||||||
@ -593,7 +590,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a_intptrHandle">Handle to lock</param>
|
/// <param name="a_intptrHandle">Handle to lock</param>
|
||||||
/// <returns>Locked pointer</returns>
|
/// <returns>Locked pointer</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public IntPtr DsmMemLock(IntPtr a_intptrHandle)
|
public IntPtr DsmMemLock(IntPtr a_intptrHandle)
|
||||||
{
|
{
|
||||||
// Validate...
|
// Validate...
|
||||||
@ -636,7 +632,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// Unlock memory used with the data source...
|
/// Unlock memory used with the data source...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a_intptrHandle">Handle to unlock</param>
|
/// <param name="a_intptrHandle">Handle to unlock</param>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public void DsmMemUnlock(IntPtr a_intptrHandle)
|
public void DsmMemUnlock(IntPtr a_intptrHandle)
|
||||||
{
|
{
|
||||||
// Validate...
|
// Validate...
|
||||||
@ -748,7 +743,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_intptrWparam">a parameter for the message</param>
|
/// <param name="a_intptrWparam">a parameter for the message</param>
|
||||||
/// <param name="a_intptrLparam">another parameter for the message</param>
|
/// <param name="a_intptrLparam">another parameter for the message</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public bool PreFilterMessage
|
public bool PreFilterMessage
|
||||||
(
|
(
|
||||||
IntPtr a_intptrHwnd,
|
IntPtr a_intptrHwnd,
|
||||||
@ -1324,13 +1318,14 @@ namespace TWAINWorkingGroup
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// DAT_IMAGENATIVEXFER...
|
// DAT_IMAGENATIVEXFER...
|
||||||
case (int)DAT.IMAGENATIVEXFER:
|
// TODO: Recode later
|
||||||
{
|
//case (int)DAT.IMAGENATIVEXFER:
|
||||||
IntPtr intptrBitmapHandle = IntPtr.Zero;
|
// {
|
||||||
sts = DatImagenativexferHandle((DG)iDg, (MSG)iMsg, ref intptrBitmapHandle);
|
// IntPtr intptrBitmapHandle = IntPtr.Zero;
|
||||||
a_szTwmemref = intptrBitmapHandle.ToString();
|
// sts = DatImagenativexferHandle((DG)iDg, (MSG)iMsg, ref intptrBitmapHandle);
|
||||||
}
|
// a_szTwmemref = intptrBitmapHandle.ToString();
|
||||||
break;
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
// DAT_JPEGCOMPRESSION...
|
// DAT_JPEGCOMPRESSION...
|
||||||
case (int)DAT.JPEGCOMPRESSION:
|
case (int)DAT.JPEGCOMPRESSION:
|
||||||
@ -1601,7 +1596,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a_twcapability">A TWAIN structure</param>
|
/// <param name="a_twcapability">A TWAIN structure</param>
|
||||||
/// <returns>A CSV string of the TWAIN structure</returns>
|
/// <returns>A CSV string of the TWAIN structure</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public string CapabilityToCsv(TW_CAPABILITY a_twcapability, bool a_blUseSymbols)
|
public string CapabilityToCsv(TW_CAPABILITY a_twcapability, bool a_blUseSymbols)
|
||||||
{
|
{
|
||||||
IntPtr intptr;
|
IntPtr intptr;
|
||||||
@ -1951,7 +1945,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_szSetting">A CSV string of the TWAIN structure</param>
|
/// <param name="a_szSetting">A CSV string of the TWAIN structure</param>
|
||||||
/// <param name="a_szValue">The container for this capability</param>
|
/// <param name="a_szValue">The container for this capability</param>
|
||||||
/// <returns>True if the conversion is successful</returns>
|
/// <returns>True if the conversion is successful</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public bool CsvToCapability(ref TW_CAPABILITY a_twcapability, ref string a_szSetting, string a_szValue)
|
public bool CsvToCapability(ref TW_CAPABILITY a_twcapability, ref string a_szSetting, string a_szValue)
|
||||||
{
|
{
|
||||||
int ii = 0;
|
int ii = 0;
|
||||||
@ -2285,7 +2278,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a_twcustomdsdata">A TWAIN structure</param>
|
/// <param name="a_twcustomdsdata">A TWAIN structure</param>
|
||||||
/// <returns>A CSV string of the TWAIN structure</returns>
|
/// <returns>A CSV string of the TWAIN structure</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public string CustomdsdataToCsv(TW_CUSTOMDSDATA a_twcustomdsdata)
|
public string CustomdsdataToCsv(TW_CUSTOMDSDATA a_twcustomdsdata)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -2310,7 +2302,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_twcustomdsdata">A TWAIN structure</param>
|
/// <param name="a_twcustomdsdata">A TWAIN structure</param>
|
||||||
/// <param name="a_szCustomdsdata">A CSV string of the TWAIN structure</param>
|
/// <param name="a_szCustomdsdata">A CSV string of the TWAIN structure</param>
|
||||||
/// <returns>True if the conversion is successful</returns>
|
/// <returns>True if the conversion is successful</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public bool CsvToCustomdsdata(ref TW_CUSTOMDSDATA a_twcustomdsdata, string a_szCustomdsdata)
|
public bool CsvToCustomdsdata(ref TW_CUSTOMDSDATA a_twcustomdsdata, string a_szCustomdsdata)
|
||||||
{
|
{
|
||||||
// Init stuff...
|
// Init stuff...
|
||||||
@ -3112,7 +3103,6 @@ namespace TWAINWorkingGroup
|
|||||||
ref m_threaddataDatAudionativexfer.intptrAudio
|
ref m_threaddataDatAudionativexfer.intptrAudio
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public STS DatAudionativexfer(DG a_dg, MSG a_msg, ref IntPtr a_intptrAudio)
|
public STS DatAudionativexfer(DG a_dg, MSG a_msg, ref IntPtr a_intptrAudio)
|
||||||
{
|
{
|
||||||
STS sts;
|
STS sts;
|
||||||
@ -3596,7 +3586,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_msg">Operation</param>
|
/// <param name="a_msg">Operation</param>
|
||||||
/// <param name="a_twcapability">CAPABILITY structure</param>
|
/// <param name="a_twcapability">CAPABILITY structure</param>
|
||||||
/// <returns>TWAIN status</returns>
|
/// <returns>TWAIN status</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
private void DatCapabilityWindowsTwain32()
|
private void DatCapabilityWindowsTwain32()
|
||||||
{
|
{
|
||||||
// If you get a first chance exception, be aware that some drivers
|
// If you get a first chance exception, be aware that some drivers
|
||||||
@ -3656,7 +3645,7 @@ namespace TWAINWorkingGroup
|
|||||||
ThreadToCallerWaitOne();
|
ThreadToCallerWaitOne();
|
||||||
|
|
||||||
// Hmmm...
|
// Hmmm...
|
||||||
if ( (a_msg == MSG.GETCURRENT)
|
if ((a_msg == MSG.GETCURRENT)
|
||||||
&& (m_twaincommand.Get(lIndex).sts == STS.SUCCESS)
|
&& (m_twaincommand.Get(lIndex).sts == STS.SUCCESS)
|
||||||
&& (m_twaincommand.Get(lIndex).twcapability.ConType == (TWON)0)
|
&& (m_twaincommand.Get(lIndex).twcapability.ConType == (TWON)0)
|
||||||
&& (m_twaincommand.Get(lIndex).twcapability.hContainer == IntPtr.Zero))
|
&& (m_twaincommand.Get(lIndex).twcapability.hContainer == IntPtr.Zero))
|
||||||
@ -4042,7 +4031,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_msg">Operation</param>
|
/// <param name="a_msg">Operation</param>
|
||||||
/// <param name="a_twcustomdsdata">CUSTOMDSDATA structure</param>
|
/// <param name="a_twcustomdsdata">CUSTOMDSDATA structure</param>
|
||||||
/// <returns>TWAIN status</returns>
|
/// <returns>TWAIN status</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public STS DatCustomdsdata(DG a_dg, MSG a_msg, ref TW_CUSTOMDSDATA a_twcustomdsdata)
|
public STS DatCustomdsdata(DG a_dg, MSG a_msg, ref TW_CUSTOMDSDATA a_twcustomdsdata)
|
||||||
{
|
{
|
||||||
STS sts;
|
STS sts;
|
||||||
@ -4333,7 +4321,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_msg">Operation</param>
|
/// <param name="a_msg">Operation</param>
|
||||||
/// <param name="a_twentrypoint">ENTRYPOINT structure</param>
|
/// <param name="a_twentrypoint">ENTRYPOINT structure</param>
|
||||||
/// <returns>TWAIN status</returns>
|
/// <returns>TWAIN status</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public STS DatEntrypoint(DG a_dg, MSG a_msg, ref TW_ENTRYPOINT a_twentrypoint)
|
public STS DatEntrypoint(DG a_dg, MSG a_msg, ref TW_ENTRYPOINT a_twentrypoint)
|
||||||
{
|
{
|
||||||
STS sts;
|
STS sts;
|
||||||
@ -4489,7 +4476,7 @@ namespace TWAINWorkingGroup
|
|||||||
m_twentrypointdelegates.DSM_Entry = a_twentrypoint.DSM_Entry;
|
m_twentrypointdelegates.DSM_Entry = a_twentrypoint.DSM_Entry;
|
||||||
if (a_twentrypoint.DSM_MemAllocate != null)
|
if (a_twentrypoint.DSM_MemAllocate != null)
|
||||||
{
|
{
|
||||||
m_twentrypointdelegates.DSM_MemAllocate = (DSM_MEMALLOC)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemAllocate,typeof(DSM_MEMALLOC));
|
m_twentrypointdelegates.DSM_MemAllocate = (DSM_MEMALLOC)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemAllocate, typeof(DSM_MEMALLOC));
|
||||||
}
|
}
|
||||||
if (a_twentrypoint.DSM_MemFree != null)
|
if (a_twentrypoint.DSM_MemFree != null)
|
||||||
{
|
{
|
||||||
@ -5554,7 +5541,6 @@ namespace TWAINWorkingGroup
|
|||||||
ref m_threaddataDatIdentity.twidentitylegacy
|
ref m_threaddataDatIdentity.twidentitylegacy
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public STS DatIdentity(DG a_dg, MSG a_msg, ref TW_IDENTITY a_twidentity)
|
public STS DatIdentity(DG a_dg, MSG a_msg, ref TW_IDENTITY a_twidentity)
|
||||||
{
|
{
|
||||||
STS sts;
|
STS sts;
|
||||||
@ -7313,220 +7299,218 @@ namespace TWAINWorkingGroup
|
|||||||
ref m_threaddataDatImagenativexfer.intptrBitmap
|
ref m_threaddataDatImagenativexfer.intptrBitmap
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
// TODO: Recode later
|
||||||
public STS DatImagenativexfer(DG a_dg, MSG a_msg, ref Bitmap a_bitmap)
|
//public STS DatImagenativexfer(DG a_dg, MSG a_msg, ref Bitmap a_bitmap)
|
||||||
{
|
//{
|
||||||
IntPtr intptrBitmapHandle = IntPtr.Zero;
|
// IntPtr intptrBitmapHandle = IntPtr.Zero;
|
||||||
return (DatImagenativexferBitmap(a_dg, a_msg, ref a_bitmap, ref intptrBitmapHandle, false));
|
// return (DatImagenativexferBitmap(a_dg, a_msg, ref a_bitmap, ref intptrBitmapHandle, false));
|
||||||
}
|
//}
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
//public STS DatImagenativexferHandle(DG a_dg, MSG a_msg, ref IntPtr a_intptrBitmapHandle)
|
||||||
public STS DatImagenativexferHandle(DG a_dg, MSG a_msg, ref IntPtr a_intptrBitmapHandle)
|
//{
|
||||||
{
|
// Bitmap bitmap = null;
|
||||||
Bitmap bitmap = null;
|
// return (DatImagenativexferBitmap(a_dg, a_msg, ref bitmap, ref a_intptrBitmapHandle, true));
|
||||||
return (DatImagenativexferBitmap(a_dg, a_msg, ref bitmap, ref a_intptrBitmapHandle, true));
|
//}
|
||||||
}
|
//public STS DatImagenativexferBitmap(DG a_dg, MSG a_msg, ref Bitmap a_bitmap, ref IntPtr a_intptrBitmapHandle, bool a_blUseBitmapHandle)
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
//{
|
||||||
public STS DatImagenativexferBitmap(DG a_dg, MSG a_msg, ref Bitmap a_bitmap, ref IntPtr a_intptrBitmapHandle, bool a_blUseBitmapHandle)
|
// STS sts;
|
||||||
{
|
// IntPtr intptrBitmap = IntPtr.Zero;
|
||||||
STS sts;
|
|
||||||
IntPtr intptrBitmap = IntPtr.Zero;
|
|
||||||
|
|
||||||
// Submit the work to the TWAIN thread...
|
// // Submit the work to the TWAIN thread...
|
||||||
if (this.m_runinuithreaddelegate == null)
|
// if (this.m_runinuithreaddelegate == null)
|
||||||
{
|
// {
|
||||||
if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId))
|
// if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId))
|
||||||
{
|
// {
|
||||||
lock (m_lockTwain)
|
// lock (m_lockTwain)
|
||||||
{
|
// {
|
||||||
// Set our command variables...
|
// // Set our command variables...
|
||||||
ThreadData threaddata = default(ThreadData);
|
// ThreadData threaddata = default(ThreadData);
|
||||||
threaddata.bitmap = a_bitmap;
|
// threaddata.bitmap = a_bitmap;
|
||||||
threaddata.blUseBitmapHandle = a_blUseBitmapHandle;
|
// threaddata.blUseBitmapHandle = a_blUseBitmapHandle;
|
||||||
threaddata.dg = a_dg;
|
// threaddata.dg = a_dg;
|
||||||
threaddata.msg = a_msg;
|
// threaddata.msg = a_msg;
|
||||||
threaddata.dat = DAT.IMAGENATIVEXFER;
|
// threaddata.dat = DAT.IMAGENATIVEXFER;
|
||||||
long lIndex = m_twaincommand.Submit(threaddata);
|
// long lIndex = m_twaincommand.Submit(threaddata);
|
||||||
|
|
||||||
// Submit the command and wait for the reply...
|
// // Submit the command and wait for the reply...
|
||||||
CallerToThreadSet();
|
// CallerToThreadSet();
|
||||||
ThreadToCallerWaitOne();
|
// ThreadToCallerWaitOne();
|
||||||
|
|
||||||
// Return the result...
|
// // Return the result...
|
||||||
a_bitmap = m_twaincommand.Get(lIndex).bitmap;
|
// a_bitmap = m_twaincommand.Get(lIndex).bitmap;
|
||||||
a_intptrBitmapHandle = m_twaincommand.Get(lIndex).intptrBitmap;
|
// a_intptrBitmapHandle = m_twaincommand.Get(lIndex).intptrBitmap;
|
||||||
sts = m_twaincommand.Get(lIndex).sts;
|
// sts = m_twaincommand.Get(lIndex).sts;
|
||||||
|
|
||||||
// Clear the command variables...
|
// // Clear the command variables...
|
||||||
m_twaincommand.Delete(lIndex);
|
// m_twaincommand.Delete(lIndex);
|
||||||
}
|
// }
|
||||||
return (sts);
|
// return (sts);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Log it...
|
// // Log it...
|
||||||
if (Log.GetLevel() > 0)
|
// if (Log.GetLevel() > 0)
|
||||||
{
|
// {
|
||||||
Log.LogSendBefore(a_dg.ToString(), DAT.IMAGENATIVEXFER.ToString(), a_msg.ToString(), "");
|
// Log.LogSendBefore(a_dg.ToString(), DAT.IMAGENATIVEXFER.ToString(), a_msg.ToString(), "");
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Windows...
|
// // Windows...
|
||||||
if (ms_platform == Platform.WINDOWS)
|
// if (ms_platform == Platform.WINDOWS)
|
||||||
{
|
// {
|
||||||
// Issue the command...
|
// // Issue the command...
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
if (m_threaddataDatImagenativexfer.blIsInuse || (this.m_runinuithreaddelegate == null))
|
// if (m_threaddataDatImagenativexfer.blIsInuse || (this.m_runinuithreaddelegate == null))
|
||||||
{
|
// {
|
||||||
if (m_blUseLegacyDSM)
|
// if (m_blUseLegacyDSM)
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.WindowsTwain32DsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.WindowsTwain32DsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.WindowsTwaindsmDsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.WindowsTwaindsmDsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
if (m_blUseLegacyDSM)
|
// if (m_blUseLegacyDSM)
|
||||||
{
|
// {
|
||||||
lock (m_lockTwain)
|
// lock (m_lockTwain)
|
||||||
{
|
// {
|
||||||
m_threaddataDatImagenativexfer = default(ThreadData);
|
// m_threaddataDatImagenativexfer = default(ThreadData);
|
||||||
m_threaddataDatImagenativexfer.blIsInuse = true;
|
// m_threaddataDatImagenativexfer.blIsInuse = true;
|
||||||
m_threaddataDatImagenativexfer.dg = a_dg;
|
// m_threaddataDatImagenativexfer.dg = a_dg;
|
||||||
m_threaddataDatImagenativexfer.msg = a_msg;
|
// m_threaddataDatImagenativexfer.msg = a_msg;
|
||||||
m_threaddataDatImagenativexfer.dat = DAT.IMAGENATIVEXFER;
|
// m_threaddataDatImagenativexfer.dat = DAT.IMAGENATIVEXFER;
|
||||||
RunInUiThread(DatImagenativexferWindowsTwain32);
|
// RunInUiThread(DatImagenativexferWindowsTwain32);
|
||||||
intptrBitmap = a_intptrBitmapHandle = m_threaddataDatImagenativexfer.intptrBitmap;
|
// intptrBitmap = a_intptrBitmapHandle = m_threaddataDatImagenativexfer.intptrBitmap;
|
||||||
sts = m_threaddataDatImagenativexfer.sts;
|
// sts = m_threaddataDatImagenativexfer.sts;
|
||||||
m_threaddataDatImagenativexfer = default(ThreadData);
|
// m_threaddataDatImagenativexfer = default(ThreadData);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
lock (m_lockTwain)
|
// lock (m_lockTwain)
|
||||||
{
|
// {
|
||||||
m_threaddataDatImagenativexfer = default(ThreadData);
|
// m_threaddataDatImagenativexfer = default(ThreadData);
|
||||||
m_threaddataDatImagenativexfer.blIsInuse = true;
|
// m_threaddataDatImagenativexfer.blIsInuse = true;
|
||||||
m_threaddataDatImagenativexfer.dg = a_dg;
|
// m_threaddataDatImagenativexfer.dg = a_dg;
|
||||||
m_threaddataDatImagenativexfer.msg = a_msg;
|
// m_threaddataDatImagenativexfer.msg = a_msg;
|
||||||
m_threaddataDatImagenativexfer.dat = DAT.IMAGENATIVEXFER;
|
// m_threaddataDatImagenativexfer.dat = DAT.IMAGENATIVEXFER;
|
||||||
RunInUiThread(DatImagenativexferWindowsTwainDsm);
|
// RunInUiThread(DatImagenativexferWindowsTwainDsm);
|
||||||
intptrBitmap = a_intptrBitmapHandle = m_threaddataDatImagenativexfer.intptrBitmap;
|
// intptrBitmap = a_intptrBitmapHandle = m_threaddataDatImagenativexfer.intptrBitmap;
|
||||||
sts = m_threaddataDatImagenativexfer.sts;
|
// sts = m_threaddataDatImagenativexfer.sts;
|
||||||
m_threaddataDatImagenativexfer = default(ThreadData);
|
// m_threaddataDatImagenativexfer = default(ThreadData);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (Exception exception)
|
// catch (Exception exception)
|
||||||
{
|
// {
|
||||||
// The driver crashed...
|
// // The driver crashed...
|
||||||
Log.Error("crash - " + exception.Message);
|
// Log.Error("crash - " + exception.Message);
|
||||||
Log.LogSendAfter(STS.BUMMER, "");
|
// Log.LogSendAfter(STS.BUMMER, "");
|
||||||
return (STS.BUMMER);
|
// return (STS.BUMMER);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Linux...
|
// // Linux...
|
||||||
else if (ms_platform == Platform.LINUX)
|
// else if (ms_platform == Platform.LINUX)
|
||||||
{
|
// {
|
||||||
// Issue the command...
|
// // Issue the command...
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
if (m_blFoundLatestDsm64 && (m_linuxdsm == LinuxDsm.IsLatestDsm))
|
// if (m_blFoundLatestDsm64 && (m_linuxdsm == LinuxDsm.IsLatestDsm))
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.Linux64DsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.Linux64DsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
else if (m_blFoundLatestDsm && (m_linuxdsm == LinuxDsm.IsLatestDsm))
|
// else if (m_blFoundLatestDsm && (m_linuxdsm == LinuxDsm.IsLatestDsm))
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.LinuxDsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.LinuxDsmEntryImagenativexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
else if (m_blFound020302Dsm64bit && (m_linuxdsm == LinuxDsm.Is020302Dsm64bit))
|
// else if (m_blFound020302Dsm64bit && (m_linuxdsm == LinuxDsm.Is020302Dsm64bit))
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.Linux020302Dsm64bitEntryImagenativexfer(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.Linux020302Dsm64bitEntryImagenativexfer(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Log.Error("apparently we don't have a DSM...");
|
// Log.Error("apparently we don't have a DSM...");
|
||||||
sts = STS.BUMMER;
|
// sts = STS.BUMMER;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (Exception exception)
|
// catch (Exception exception)
|
||||||
{
|
// {
|
||||||
// The driver crashed...
|
// // The driver crashed...
|
||||||
Log.Error("crash - " + exception.Message);
|
// Log.Error("crash - " + exception.Message);
|
||||||
Log.LogSendAfter(STS.BUMMER, "");
|
// Log.LogSendAfter(STS.BUMMER, "");
|
||||||
return (STS.BUMMER);
|
// return (STS.BUMMER);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Mac OS X, which has to be different...
|
// // Mac OS X, which has to be different...
|
||||||
else if (ms_platform == Platform.MACOSX)
|
// else if (ms_platform == Platform.MACOSX)
|
||||||
{
|
// {
|
||||||
// Issue the command...
|
// // Issue the command...
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
intptrBitmap = IntPtr.Zero;
|
// intptrBitmap = IntPtr.Zero;
|
||||||
if (m_blUseLegacyDSM)
|
// if (m_blUseLegacyDSM)
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.MacosxTwainDsmEntryImagenativexfer(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.MacosxTwainDsmEntryImagenativexfer(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
sts = (STS)NativeMethods.MacosxTwaindsmDsmEntryImagenativexfer(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
// sts = (STS)NativeMethods.MacosxTwaindsmDsmEntryImagenativexfer(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.IMAGENATIVEXFER, a_msg, ref intptrBitmap);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (Exception exception)
|
// catch (Exception exception)
|
||||||
{
|
// {
|
||||||
// The driver crashed...
|
// // The driver crashed...
|
||||||
Log.Error("crash - " + exception.Message);
|
// Log.Error("crash - " + exception.Message);
|
||||||
Log.LogSendAfter(STS.BUMMER, "");
|
// Log.LogSendAfter(STS.BUMMER, "");
|
||||||
return (STS.BUMMER);
|
// return (STS.BUMMER);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Uh-oh...
|
// // Uh-oh...
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Log.LogSendAfter(STS.BUMMER, "");
|
// Log.LogSendAfter(STS.BUMMER, "");
|
||||||
return (STS.BUMMER);
|
// return (STS.BUMMER);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Get DAT_STATUS, if needed...
|
// // Get DAT_STATUS, if needed...
|
||||||
STS stsRcOrCc = AutoDatStatus(sts);
|
// STS stsRcOrCc = AutoDatStatus(sts);
|
||||||
|
|
||||||
// Log it...
|
// // Log it...
|
||||||
if (Log.GetLevel() > 0)
|
// if (Log.GetLevel() > 0)
|
||||||
{
|
// {
|
||||||
Log.LogSendAfter(stsRcOrCc, "");
|
// Log.LogSendAfter(stsRcOrCc, "");
|
||||||
}
|
// }
|
||||||
|
|
||||||
// If we had a successful transfer, then convert the data...
|
// // If we had a successful transfer, then convert the data...
|
||||||
if (sts == STS.XFERDONE)
|
// if (sts == STS.XFERDONE)
|
||||||
{
|
// {
|
||||||
if (a_blUseBitmapHandle)
|
// if (a_blUseBitmapHandle)
|
||||||
{
|
// {
|
||||||
a_intptrBitmapHandle = intptrBitmap;
|
// a_intptrBitmapHandle = intptrBitmap;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// Bump our state...
|
// // Bump our state...
|
||||||
m_state = STATE.S7;
|
// m_state = STATE.S7;
|
||||||
|
|
||||||
// Turn the DIB into a Bitmap object...
|
// // Turn the DIB into a Bitmap object...
|
||||||
a_bitmap = NativeToBitmap(ms_platform, intptrBitmap);
|
// a_bitmap = NativeToBitmap(ms_platform, intptrBitmap);
|
||||||
|
|
||||||
// We're done with the data we got from the driver...
|
// // We're done with the data we got from the driver...
|
||||||
Marshal.FreeHGlobal(intptrBitmap);
|
// Marshal.FreeHGlobal(intptrBitmap);
|
||||||
intptrBitmap = IntPtr.Zero;
|
// intptrBitmap = IntPtr.Zero;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// All done...
|
// // All done...
|
||||||
return (stsRcOrCc);
|
// return (stsRcOrCc);
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get/Set JPEG compression tables...
|
/// Get/Set JPEG compression tables...
|
||||||
@ -7998,7 +7982,6 @@ namespace TWAINWorkingGroup
|
|||||||
ref m_threaddataDatParent.intptrHwnd
|
ref m_threaddataDatParent.intptrHwnd
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public STS DatParent(DG a_dg, MSG a_msg, ref IntPtr a_intptrHwnd)
|
public STS DatParent(DG a_dg, MSG a_msg, ref IntPtr a_intptrHwnd)
|
||||||
{
|
{
|
||||||
STS sts;
|
STS sts;
|
||||||
@ -10720,16 +10703,17 @@ namespace TWAINWorkingGroup
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// Native transfer...
|
// Native transfer...
|
||||||
case DAT.IMAGENATIVEXFER:
|
// TODO: Recode later
|
||||||
if (threaddata.blUseBitmapHandle)
|
//case DAT.IMAGENATIVEXFER:
|
||||||
{
|
// if (threaddata.blUseBitmapHandle)
|
||||||
threaddata.sts = DatImagenativexferHandle(threaddata.dg, threaddata.msg, ref threaddata.intptrBitmap);
|
// {
|
||||||
}
|
// threaddata.sts = DatImagenativexferHandle(threaddata.dg, threaddata.msg, ref threaddata.intptrBitmap);
|
||||||
else
|
// }
|
||||||
{
|
// else
|
||||||
threaddata.sts = DatImagenativexfer(threaddata.dg, threaddata.msg, ref threaddata.bitmap);
|
// {
|
||||||
}
|
// threaddata.sts = DatImagenativexfer(threaddata.dg, threaddata.msg, ref threaddata.bitmap);
|
||||||
break;
|
// }
|
||||||
|
// break;
|
||||||
|
|
||||||
// JPEG compression...
|
// JPEG compression...
|
||||||
case DAT.JPEGCOMPRESSION:
|
case DAT.JPEGCOMPRESSION:
|
||||||
@ -11189,7 +11173,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_intptr">Pointer to the data</param>
|
/// <param name="a_intptr">Pointer to the data</param>
|
||||||
/// <param name="a_iIndex">Index of the item in the data</param>
|
/// <param name="a_iIndex">Index of the item in the data</param>
|
||||||
/// <returns>Data in CSV form</returns>
|
/// <returns>Data in CSV form</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public string GetIndexedItem(TW_CAPABILITY a_twcapability, TWTY a_twty, IntPtr a_intptr, int a_iIndex)
|
public string GetIndexedItem(TW_CAPABILITY a_twcapability, TWTY a_twty, IntPtr a_intptr, int a_iIndex)
|
||||||
{
|
{
|
||||||
IntPtr intptr;
|
IntPtr intptr;
|
||||||
@ -11301,7 +11284,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_iIndex">Index for item in the data</param>
|
/// <param name="a_iIndex">Index for item in the data</param>
|
||||||
/// <param name="a_szValue">CSV value to be used to set the data</param>
|
/// <param name="a_szValue">CSV value to be used to set the data</param>
|
||||||
/// <returns>Empty string or an error string</returns>
|
/// <returns>Empty string or an error string</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public string SetIndexedItem(TW_CAPABILITY a_twcapability, TWTY a_twty, IntPtr a_intptr, int a_iIndex, string a_szValue)
|
public string SetIndexedItem(TW_CAPABILITY a_twcapability, TWTY a_twty, IntPtr a_intptr, int a_iIndex, string a_szValue)
|
||||||
{
|
{
|
||||||
IntPtr intptr;
|
IntPtr intptr;
|
||||||
@ -11479,7 +11461,6 @@ namespace TWAINWorkingGroup
|
|||||||
/// <param name="a_intptr">Pointer to the data</param>
|
/// <param name="a_intptr">Pointer to the data</param>
|
||||||
/// <param name="a_asz">List of strings</param>
|
/// <param name="a_asz">List of strings</param>
|
||||||
/// <returns>Empty string or an error string</returns>
|
/// <returns>Empty string or an error string</returns>
|
||||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust", Unrestricted = false)]
|
|
||||||
public string SetRangeItem(TWTY a_twty, IntPtr a_intptr, string[] a_asz)
|
public string SetRangeItem(TWTY a_twty, IntPtr a_intptr, string[] a_asz)
|
||||||
{
|
{
|
||||||
TW_RANGE twrange = default(TW_RANGE);
|
TW_RANGE twrange = default(TW_RANGE);
|
||||||
@ -11819,167 +11800,167 @@ namespace TWAINWorkingGroup
|
|||||||
return ((UInt16)STS.SUCCESS);
|
return ((UInt16)STS.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// Get .NET 'Bitmap' object from memory DIB via stream constructor.
|
///// Get .NET 'Bitmap' object from memory DIB via stream constructor.
|
||||||
/// This should work for most DIBs.
|
///// This should work for most DIBs.
|
||||||
/// </summary>
|
///// </summary>
|
||||||
/// <param name="a_platform">Our operating system</param>
|
///// <param name="a_platform">Our operating system</param>
|
||||||
/// <param name="a_intptrNative">The pointer to something (presumably a BITMAP or a TIFF image)</param>
|
///// <param name="a_intptrNative">The pointer to something (presumably a BITMAP or a TIFF image)</param>
|
||||||
/// <returns>C# Bitmap of image</returns>
|
///// <returns>C# Bitmap of image</returns>
|
||||||
private Bitmap NativeToBitmap(Platform a_platform, IntPtr a_intptrNative)
|
//private Bitmap NativeToBitmap(Platform a_platform, IntPtr a_intptrNative)
|
||||||
{
|
//{
|
||||||
ushort u16Magic;
|
// ushort u16Magic;
|
||||||
IntPtr intptrNative;
|
// IntPtr intptrNative;
|
||||||
|
|
||||||
// We need the first two bytes to decide if we have a DIB or a TIFF. Don't
|
// // We need the first two bytes to decide if we have a DIB or a TIFF. Don't
|
||||||
// forget to lock the silly thing...
|
// // forget to lock the silly thing...
|
||||||
intptrNative = DsmMemLock(a_intptrNative);
|
// intptrNative = DsmMemLock(a_intptrNative);
|
||||||
u16Magic = (ushort)Marshal.PtrToStructure(intptrNative, typeof(ushort));
|
// u16Magic = (ushort)Marshal.PtrToStructure(intptrNative, typeof(ushort));
|
||||||
|
|
||||||
// Windows uses a DIB, the first usigned short is 40...
|
// // Windows uses a DIB, the first usigned short is 40...
|
||||||
if (u16Magic == 40)
|
// if (u16Magic == 40)
|
||||||
{
|
// {
|
||||||
byte[] bBitmap;
|
// byte[] bBitmap;
|
||||||
BITMAPFILEHEADER bitmapfileheader;
|
// BITMAPFILEHEADER bitmapfileheader;
|
||||||
BITMAPINFOHEADER bitmapinfoheader;
|
// BITMAPINFOHEADER bitmapinfoheader;
|
||||||
|
|
||||||
// Our incoming DIB is a bitmap info header...
|
// // Our incoming DIB is a bitmap info header...
|
||||||
bitmapinfoheader = (BITMAPINFOHEADER)Marshal.PtrToStructure(intptrNative, typeof(BITMAPINFOHEADER));
|
// bitmapinfoheader = (BITMAPINFOHEADER)Marshal.PtrToStructure(intptrNative, typeof(BITMAPINFOHEADER));
|
||||||
|
|
||||||
// Build our file header...
|
// // Build our file header...
|
||||||
bitmapfileheader = new BITMAPFILEHEADER();
|
// bitmapfileheader = new BITMAPFILEHEADER();
|
||||||
bitmapfileheader.bfType = 0x4D42; // "BM"
|
// bitmapfileheader.bfType = 0x4D42; // "BM"
|
||||||
bitmapfileheader.bfSize
|
// bitmapfileheader.bfSize
|
||||||
= (uint)Marshal.SizeOf(typeof(BITMAPFILEHEADER)) +
|
// = (uint)Marshal.SizeOf(typeof(BITMAPFILEHEADER)) +
|
||||||
bitmapinfoheader.biSize +
|
// bitmapinfoheader.biSize +
|
||||||
(bitmapinfoheader.biClrUsed * 4) +
|
// (bitmapinfoheader.biClrUsed * 4) +
|
||||||
bitmapinfoheader.biSizeImage;
|
// bitmapinfoheader.biSizeImage;
|
||||||
bitmapfileheader.bfOffBits
|
// bitmapfileheader.bfOffBits
|
||||||
= (uint)Marshal.SizeOf(typeof(BITMAPFILEHEADER)) +
|
// = (uint)Marshal.SizeOf(typeof(BITMAPFILEHEADER)) +
|
||||||
bitmapinfoheader.biSize +
|
// bitmapinfoheader.biSize +
|
||||||
(bitmapinfoheader.biClrUsed * 4);
|
// (bitmapinfoheader.biClrUsed * 4);
|
||||||
|
|
||||||
// Copy the file header into our byte array...
|
// // Copy the file header into our byte array...
|
||||||
IntPtr intptr = Marshal.AllocHGlobal(Marshal.SizeOf(bitmapfileheader));
|
// IntPtr intptr = Marshal.AllocHGlobal(Marshal.SizeOf(bitmapfileheader));
|
||||||
Marshal.StructureToPtr(bitmapfileheader, intptr, true);
|
// Marshal.StructureToPtr(bitmapfileheader, intptr, true);
|
||||||
bBitmap = new byte[bitmapfileheader.bfSize];
|
// bBitmap = new byte[bitmapfileheader.bfSize];
|
||||||
Marshal.Copy(intptr, bBitmap, 0, Marshal.SizeOf(bitmapfileheader));
|
// Marshal.Copy(intptr, bBitmap, 0, Marshal.SizeOf(bitmapfileheader));
|
||||||
Marshal.FreeHGlobal(intptr);
|
// Marshal.FreeHGlobal(intptr);
|
||||||
intptr = IntPtr.Zero;
|
// intptr = IntPtr.Zero;
|
||||||
|
|
||||||
// Copy the rest of the DIB into our byte array......
|
// // Copy the rest of the DIB into our byte array......
|
||||||
Marshal.Copy(intptrNative, bBitmap, Marshal.SizeOf(typeof(BITMAPFILEHEADER)), (int)bitmapfileheader.bfSize - Marshal.SizeOf(typeof(BITMAPFILEHEADER)));
|
// Marshal.Copy(intptrNative, bBitmap, Marshal.SizeOf(typeof(BITMAPFILEHEADER)), (int)bitmapfileheader.bfSize - Marshal.SizeOf(typeof(BITMAPFILEHEADER)));
|
||||||
|
|
||||||
// Now we can turn the in-memory bitmap file into a Bitmap object...
|
// // Now we can turn the in-memory bitmap file into a Bitmap object...
|
||||||
MemoryStream memorystream = new MemoryStream(bBitmap);
|
// MemoryStream memorystream = new MemoryStream(bBitmap);
|
||||||
|
|
||||||
// Unfortunately the stream has to be kept with the bitmap...
|
// // Unfortunately the stream has to be kept with the bitmap...
|
||||||
Bitmap bitmapStream = new Bitmap(memorystream);
|
// Bitmap bitmapStream = new Bitmap(memorystream);
|
||||||
|
|
||||||
// So we make a copy (ick)...
|
// // So we make a copy (ick)...
|
||||||
Bitmap bitmap;
|
// Bitmap bitmap;
|
||||||
switch (bitmapinfoheader.biBitCount)
|
// switch (bitmapinfoheader.biBitCount)
|
||||||
{
|
// {
|
||||||
default:
|
// default:
|
||||||
case 24:
|
// case 24:
|
||||||
bitmap = bitmapStream.Clone(new Rectangle(0, 0, bitmapStream.Width, bitmapStream.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
// bitmap = bitmapStream.Clone(new Rectangle(0, 0, bitmapStream.Width, bitmapStream.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
||||||
break;
|
// break;
|
||||||
case 8:
|
// case 8:
|
||||||
bitmap = bitmapStream.Clone(new Rectangle(0, 0, bitmapStream.Width, bitmapStream.Height), System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
|
// bitmap = bitmapStream.Clone(new Rectangle(0, 0, bitmapStream.Width, bitmapStream.Height), System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
|
||||||
break;
|
// break;
|
||||||
case 1:
|
// case 1:
|
||||||
bitmap = bitmapStream.Clone(new Rectangle(0, 0, bitmapStream.Width, bitmapStream.Height), System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
|
// bitmap = bitmapStream.Clone(new Rectangle(0, 0, bitmapStream.Width, bitmapStream.Height), System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Fix the resolution...
|
// // Fix the resolution...
|
||||||
bitmap.SetResolution((int)(bitmap.HorizontalResolution + 0.5), (int)(bitmap.VerticalResolution + 0.5));
|
// bitmap.SetResolution((int)(bitmap.HorizontalResolution + 0.5), (int)(bitmap.VerticalResolution + 0.5));
|
||||||
|
|
||||||
// Cleanup...
|
// // Cleanup...
|
||||||
//bitmapStream.Dispose();
|
// //bitmapStream.Dispose();
|
||||||
//memorystream.Close();
|
// //memorystream.Close();
|
||||||
bitmapStream = null;
|
// bitmapStream = null;
|
||||||
memorystream = null;
|
// memorystream = null;
|
||||||
bBitmap = null;
|
// bBitmap = null;
|
||||||
|
|
||||||
// Return our bitmap...
|
// // Return our bitmap...
|
||||||
DsmMemUnlock(a_intptrNative);
|
// DsmMemUnlock(a_intptrNative);
|
||||||
return (bitmap);
|
// return (bitmap);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Linux and Mac OS X use TIFF. We'll handle a simple Intel TIFF ("II")...
|
// // Linux and Mac OS X use TIFF. We'll handle a simple Intel TIFF ("II")...
|
||||||
else if (u16Magic == 0x4949)
|
// else if (u16Magic == 0x4949)
|
||||||
{
|
// {
|
||||||
int iTiffSize;
|
// int iTiffSize;
|
||||||
ulong u64;
|
// ulong u64;
|
||||||
ulong u64Pointer;
|
// ulong u64Pointer;
|
||||||
ulong u64TiffHeaderSize;
|
// ulong u64TiffHeaderSize;
|
||||||
ulong u64TiffTagSize;
|
// ulong u64TiffTagSize;
|
||||||
byte[] abTiff;
|
// byte[] abTiff;
|
||||||
TIFFHEADER tiffheader;
|
// TIFFHEADER tiffheader;
|
||||||
TIFFTAG tifftag;
|
// TIFFTAG tifftag;
|
||||||
|
|
||||||
// Init stuff...
|
// // Init stuff...
|
||||||
tiffheader = new TIFFHEADER();
|
// tiffheader = new TIFFHEADER();
|
||||||
tifftag = new TIFFTAG();
|
// tifftag = new TIFFTAG();
|
||||||
u64TiffHeaderSize = (ulong)Marshal.SizeOf(tiffheader);
|
// u64TiffHeaderSize = (ulong)Marshal.SizeOf(tiffheader);
|
||||||
u64TiffTagSize = (ulong)Marshal.SizeOf(tifftag);
|
// u64TiffTagSize = (ulong)Marshal.SizeOf(tifftag);
|
||||||
|
|
||||||
// Find the size of the image so we can turn it into a memory stream...
|
// // Find the size of the image so we can turn it into a memory stream...
|
||||||
iTiffSize = 0;
|
// iTiffSize = 0;
|
||||||
tiffheader = (TIFFHEADER)Marshal.PtrToStructure(intptrNative, typeof(TIFFHEADER));
|
// tiffheader = (TIFFHEADER)Marshal.PtrToStructure(intptrNative, typeof(TIFFHEADER));
|
||||||
for (u64 = 0; u64 < 999; u64++)
|
// for (u64 = 0; u64 < 999; u64++)
|
||||||
{
|
// {
|
||||||
u64Pointer = (ulong)intptrNative + u64TiffHeaderSize + (u64TiffTagSize * u64);
|
// u64Pointer = (ulong)intptrNative + u64TiffHeaderSize + (u64TiffTagSize * u64);
|
||||||
tifftag = (TIFFTAG)Marshal.PtrToStructure((IntPtr)u64Pointer, typeof(TIFFTAG));
|
// tifftag = (TIFFTAG)Marshal.PtrToStructure((IntPtr)u64Pointer, typeof(TIFFTAG));
|
||||||
|
|
||||||
// StripOffsets...
|
// // StripOffsets...
|
||||||
if (tifftag.u16Tag == 273)
|
// if (tifftag.u16Tag == 273)
|
||||||
{
|
// {
|
||||||
iTiffSize += (int)tifftag.u32Value;
|
// iTiffSize += (int)tifftag.u32Value;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// StripByteCounts...
|
// // StripByteCounts...
|
||||||
if (tifftag.u16Tag == 279)
|
// if (tifftag.u16Tag == 279)
|
||||||
{
|
// {
|
||||||
iTiffSize += (int)tifftag.u32Value;
|
// iTiffSize += (int)tifftag.u32Value;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// No joy...
|
// // No joy...
|
||||||
if (iTiffSize == 0)
|
// if (iTiffSize == 0)
|
||||||
{
|
// {
|
||||||
DsmMemUnlock(a_intptrNative);
|
// DsmMemUnlock(a_intptrNative);
|
||||||
return (null);
|
// return (null);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Copy the data to our byte array...
|
// // Copy the data to our byte array...
|
||||||
abTiff = new byte[iTiffSize];
|
// abTiff = new byte[iTiffSize];
|
||||||
Marshal.Copy(intptrNative, abTiff, 0, iTiffSize);
|
// Marshal.Copy(intptrNative, abTiff, 0, iTiffSize);
|
||||||
|
|
||||||
// Move the image into a memory stream...
|
// // Move the image into a memory stream...
|
||||||
MemoryStream memorystream = new MemoryStream(abTiff);
|
// MemoryStream memorystream = new MemoryStream(abTiff);
|
||||||
|
|
||||||
// Turn the memory stream into an in-memory TIFF image...
|
// // Turn the memory stream into an in-memory TIFF image...
|
||||||
Image imageTiff = Image.FromStream(memorystream);
|
// Image imageTiff = Image.FromStream(memorystream);
|
||||||
|
|
||||||
// Convert the in-memory tiff to a Bitmap object...
|
// // Convert the in-memory tiff to a Bitmap object...
|
||||||
Bitmap bitmap = new Bitmap(imageTiff);
|
// Bitmap bitmap = new Bitmap(imageTiff);
|
||||||
|
|
||||||
// Cleanup...
|
// // Cleanup...
|
||||||
abTiff = null;
|
// abTiff = null;
|
||||||
memorystream = null;
|
// memorystream = null;
|
||||||
imageTiff = null;
|
// imageTiff = null;
|
||||||
|
|
||||||
// Return our bitmap...
|
// // Return our bitmap...
|
||||||
DsmMemUnlock(a_intptrNative);
|
// DsmMemUnlock(a_intptrNative);
|
||||||
return (bitmap);
|
// return (bitmap);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Uh-oh...
|
// // Uh-oh...
|
||||||
DsmMemUnlock(a_intptrNative);
|
// DsmMemUnlock(a_intptrNative);
|
||||||
return (null);
|
// return (null);
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get .NET 'Bitmap' object from memory DIB via stream constructor.
|
/// Get .NET 'Bitmap' object from memory DIB via stream constructor.
|
||||||
@ -12316,8 +12297,9 @@ namespace TWAINWorkingGroup
|
|||||||
public IntPtr intptrBitmap;
|
public IntPtr intptrBitmap;
|
||||||
public IntPtr intptrAudio;
|
public IntPtr intptrAudio;
|
||||||
public IntPtr twmemref;
|
public IntPtr twmemref;
|
||||||
public Bitmap bitmap;
|
// TODO: Recode later
|
||||||
public bool blUseBitmapHandle;
|
//public Bitmap bitmap;
|
||||||
|
//public bool blUseBitmapHandle;
|
||||||
public UInt32 twuint32;
|
public UInt32 twuint32;
|
||||||
public TW_AUDIOINFO twaudioinfo;
|
public TW_AUDIOINFO twaudioinfo;
|
||||||
public TW_CALLBACK twcallback;
|
public TW_CALLBACK twcallback;
|
||||||
@ -12729,7 +12711,7 @@ namespace TWAINWorkingGroup
|
|||||||
a_threaddata = default(ThreadData);
|
a_threaddata = default(ThreadData);
|
||||||
|
|
||||||
// Cycle once through the commands to see if we have any...
|
// Cycle once through the commands to see if we have any...
|
||||||
for (;;)
|
for (; ; )
|
||||||
{
|
{
|
||||||
// We found something, copy it out, point to the next
|
// We found something, copy it out, point to the next
|
||||||
// item (so we know we're looking at the whole list)
|
// item (so we know we're looking at the whole list)
|
||||||
@ -12771,7 +12753,7 @@ namespace TWAINWorkingGroup
|
|||||||
long ll;
|
long ll;
|
||||||
|
|
||||||
// We won't leave until we've submitted the beastie...
|
// We won't leave until we've submitted the beastie...
|
||||||
for (;;)
|
for (; ; )
|
||||||
{
|
{
|
||||||
// Look for a free slot...
|
// Look for a free slot...
|
||||||
for (ll = 0; ll < m_athreaddata.Length; ll++)
|
for (ll = 0; ll < m_athreaddata.Length; ll++)
|
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