Add net5.0-windows build on x86 apps for now.

This commit is contained in:
Eugene Wang
2021-02-02 12:03:48 -05:00
parent 2e3f7422df
commit 06eb14545b
10 changed files with 2010 additions and 4 deletions

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>