Skip to content

Commit

Permalink
Add net5.0-windows build on x86 apps for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
soukoku committed Feb 2, 2021
1 parent 2e3f742 commit 06eb145
Show file tree
Hide file tree
Showing 10 changed files with 2,010 additions and 4 deletions.
30 changes: 30 additions & 0 deletions NTwain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Console", "samples\S
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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Net5Winform", "samples\Sample.Net5Winform\Sample.Net5Winform.csproj", "{5DA59B03-A286-4BC4-9F85-CDE893BB6C6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -83,6 +87,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
{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
Expand All @@ -92,6 +120,8 @@ 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}
Expand Down
107 changes: 107 additions & 0 deletions samples/Sample.Net5Console/Program.cs
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);
}
}

}
}
13 changes: 13 additions & 0 deletions samples/Sample.Net5Console/Sample.Net5Console.csproj
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>
23 changes: 23 additions & 0 deletions samples/Sample.Net5Winform/Program.cs
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());
}
}
}
15 changes: 15 additions & 0 deletions samples/Sample.Net5Winform/Sample.Net5Winform.csproj
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>
Loading

0 comments on commit 06eb145

Please sign in to comment.