-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add net5.0-windows build on x86 apps for now.
- Loading branch information
Showing
10 changed files
with
2,010 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.