mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-08 02:24:46 +08:00
Made framework 4 the default and added fx3 as old.
This commit is contained in:
@@ -707,7 +707,7 @@ namespace NTwain.Data
|
||||
ContainerType = Values.ContainerType.Enum;
|
||||
|
||||
|
||||
Int32 valueSize = value.ItemOffset + value.ItemList.Length * TypeReader.GetItemTypeSize(value.ItemType);
|
||||
Int32 valueSize = TWEnumeration.ItemOffset + value.ItemList.Length * TypeReader.GetItemTypeSize(value.ItemType);
|
||||
|
||||
int offset = 0;
|
||||
_hContainer = MemoryManager.Instance.Allocate((uint)valueSize);
|
||||
@@ -817,7 +817,7 @@ namespace NTwain.Data
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="maxLength"></param>
|
||||
private void WriteString(IntPtr baseAddr, int offset, string item, int maxLength)
|
||||
static void WriteString(IntPtr baseAddr, int offset, string item, int maxLength)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item))
|
||||
{
|
||||
@@ -1262,7 +1262,7 @@ namespace NTwain.Data
|
||||
/// <summary>
|
||||
/// Gets the byte offset of the item list from a Ptr to the first item.
|
||||
/// </summary>
|
||||
internal int ItemOffset { get { return 14; } }
|
||||
internal const int ItemOffset = 14;
|
||||
}
|
||||
|
||||
|
||||
@@ -1686,7 +1686,7 @@ namespace NTwain.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="TWIdentity"/> from specified values.
|
||||
/// Creates a <see cref="TWIdentity" /> from specified values.
|
||||
/// </summary>
|
||||
/// <param name="supportedGroups">The supported groups.</param>
|
||||
/// <param name="version">The version.</param>
|
||||
@@ -1695,9 +1695,12 @@ namespace NTwain.Data
|
||||
/// <param name="productName">Name of the product.</param>
|
||||
/// <param name="productDescription">The product description.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException">version</exception>
|
||||
public static TWIdentity Create(DataGroups supportedGroups, Version version,
|
||||
string manufacturer, string productFamily, string productName, string productDescription)
|
||||
{
|
||||
if (version == null) { throw new ArgumentNullException("version"); }
|
||||
|
||||
return new TWIdentity
|
||||
{
|
||||
Manufacturer = string.IsNullOrEmpty(manufacturer) ? "UNKNOWN" : manufacturer,
|
||||
@@ -1796,7 +1799,7 @@ namespace NTwain.Data
|
||||
/// The compression method used to process the data being transferred.
|
||||
/// Default is no compression.
|
||||
/// </summary>
|
||||
public Compression Compression { get { return (Values.Compression)_compression; } }
|
||||
public CompressionType Compression { get { return (Values.CompressionType)_compression; } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1877,7 +1880,7 @@ namespace NTwain.Data
|
||||
/// <summary>
|
||||
/// The compression method used to process the data being transferred.
|
||||
/// </summary>
|
||||
public Compression Compression { get { return (Compression)_compression; } }
|
||||
public CompressionType Compression { get { return (CompressionType)_compression; } }
|
||||
/// <summary>
|
||||
/// The number of uncompressed bytes in each row of the piece of the image
|
||||
/// being described in this buffer.
|
||||
@@ -2221,10 +2224,10 @@ namespace NTwain.Data
|
||||
/// TwIdentity.Language or CapLanguage). The Source allocates
|
||||
/// it, the Application frees it.
|
||||
/// </summary>
|
||||
IntPtr UTF8StringPtr { get { return _uTF8string; } }
|
||||
public IntPtr UTF8StringPtr { get { return _uTF8string; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the actual string from the pointer.
|
||||
/// Gets the actual string from the pointer. This may be incorrect.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetActualString()
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace NTwain
|
||||
if (_dispatcher == null)
|
||||
{
|
||||
// using this terrible hack so the new thread will start running before this function returns
|
||||
using (var hack = new ManualResetEvent(false))
|
||||
using (var hack = new WrappedManualResetEvent())
|
||||
{
|
||||
var loopThread = new Thread(new ThreadStart(() =>
|
||||
{
|
||||
@@ -49,7 +49,7 @@ namespace NTwain
|
||||
loopThread.IsBackground = true;
|
||||
loopThread.SetApartmentState(ApartmentState.STA);
|
||||
loopThread.Start();
|
||||
hack.WaitOne();
|
||||
hack.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ namespace NTwain
|
||||
}
|
||||
else if (Dsm.IsOnMono)
|
||||
{
|
||||
using (var man = new ManualResetEvent(false))
|
||||
using (var man = new WrappedManualResetEvent())
|
||||
{
|
||||
_dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
@@ -92,7 +92,7 @@ namespace NTwain
|
||||
man.Set();
|
||||
}
|
||||
}));
|
||||
man.WaitOne();
|
||||
man.Wait();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -117,16 +117,24 @@ namespace NTwain
|
||||
// hook into windows msg loop for old twain to post msgs.
|
||||
// the style values are purely guesses here with
|
||||
// CS_NOCLOSE, WS_DISABLED, and WS_EX_NOACTIVATE
|
||||
var win = new HwndSource(0x0200, 0x8000000, 0x8000000, 0, 0, "NTWAIN_LOOPER", IntPtr.Zero);
|
||||
Handle = win.Handle;
|
||||
win.AddHook(WndProc);
|
||||
_win = win;
|
||||
_hook = hook;
|
||||
HwndSource win = null;
|
||||
try
|
||||
{
|
||||
win = new HwndSource(0x0200, 0x8000000, 0x8000000, 0, 0, "NTWAIN_LOOPER", IntPtr.Zero);
|
||||
Handle = win.Handle;
|
||||
win.AddHook(WndProc);
|
||||
_win = win;
|
||||
_hook = hook;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (win != null) { win.Dispose(); }
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void WndProcHook(ref MESSAGE winMsg, ref bool handled);
|
||||
|
||||
|
||||
|
||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
if (_hook != null)
|
||||
@@ -180,4 +188,55 @@ namespace NTwain
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
// just a test
|
||||
|
||||
class WrappedManualResetEvent : IDisposable
|
||||
{
|
||||
#if NET4
|
||||
ManualResetEventSlim _slim;
|
||||
#else
|
||||
ManualResetEvent _mre;
|
||||
#endif
|
||||
|
||||
public WrappedManualResetEvent()
|
||||
{
|
||||
#if NET4
|
||||
_slim = new ManualResetEventSlim();
|
||||
#else
|
||||
_mre = new ManualResetEvent(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Wait()
|
||||
{
|
||||
#if NET4
|
||||
_slim.Wait();
|
||||
#else
|
||||
_mre.WaitOne();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Set()
|
||||
{
|
||||
#if NET4
|
||||
_slim.Set();
|
||||
#else
|
||||
_mre.Set();
|
||||
#endif
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
#if NET4
|
||||
_slim.Dispose();
|
||||
#else
|
||||
_mre.Close();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NTwain</RootNamespace>
|
||||
<AssemblyName>NTwain</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
@@ -33,11 +33,12 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;WIN32</DefineConstants>
|
||||
<DefineConstants>TRACE;NET4</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\NTwain.xml</DocumentationFile>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
@@ -48,8 +49,6 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
<tags>twain scan</tags>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="bin\$configuration$\$id$.pdb" target="lib\net35-client"/>
|
||||
<!--<file src="bin\$configuration$\Net4\$id$.dll" target="lib\net40-client"/>
|
||||
<file src="bin\$configuration$\Net4\$id$.xml" target="lib\net40-client"/>
|
||||
<file src="bin\$configuration$\Net4\$id$.pdb" target="lib\net40-client"/>-->
|
||||
<file src="bin\$configuration$\$id$.pdb" target="lib\net40-client"/>
|
||||
<file src="bin\$configuration$\Net35\$id$.dll" target="lib\net35-client"/>
|
||||
<file src="bin\$configuration$\Net35\$id$.xml" target="lib\net35-client"/>
|
||||
<file src="bin\$configuration$\Net35\$id$.pdb" target="lib\net35-client"/>
|
||||
</files>
|
||||
</package>
|
||||
@@ -1,6 +1,7 @@
|
||||
using NTwain.Data;
|
||||
using NTwain.Values;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace NTwain.Triplets
|
||||
{
|
||||
@@ -27,9 +28,8 @@ namespace NTwain.Triplets
|
||||
return IntPtr.Size == 8;
|
||||
#else
|
||||
var path = Path.Combine(Environment.SystemDirectory, "twaindsm.dll");
|
||||
// if 64bit or the dll exists use it
|
||||
return IntPtr.Size == 8 ||
|
||||
File.Exists(path);
|
||||
// if 64bit or the new dll exists use it
|
||||
return IntPtr.Size == 8 || File.Exists(path);
|
||||
#endif
|
||||
}
|
||||
internal static readonly bool IsOnMono = Type.GetType("Mono.Runtime") != null;
|
||||
|
||||
@@ -213,14 +213,14 @@ namespace NTwain
|
||||
#region compression
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported <see cref="Compression"/> for the current source.
|
||||
/// Gets the supported <see cref="CompressionType"/> for the current source.
|
||||
/// Only call this at state 4 or higher.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <returns></returns>
|
||||
public static IList<Compression> CapGetCompression(this TwainSession session)
|
||||
public static IList<CompressionType> CapGetCompression(this TwainSession session)
|
||||
{
|
||||
return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<Compression>(true);
|
||||
return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<CompressionType>(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -229,7 +229,7 @@ namespace NTwain
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="compression">The compression.</param>
|
||||
/// <returns></returns>
|
||||
public static ReturnCode CapSetImageCompression(this TwainSession session, Compression compression)
|
||||
public static ReturnCode CapSetImageCompression(this TwainSession session, CompressionType compression)
|
||||
{
|
||||
using (TWCapability compressCap = new TWCapability(CapabilityId.ICapCompression, new TWOneValue { Item = (uint)compression, ItemType = Values.ItemType.UInt16 }))
|
||||
{
|
||||
|
||||
@@ -267,7 +267,7 @@ namespace NTwain.Values
|
||||
/// setting the desired file format with ICAP_IMAGEFILEFORMAT.
|
||||
/// Corresponds to TWCP_* values.
|
||||
/// </summary>
|
||||
public enum Compression : ushort
|
||||
public enum CompressionType : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// All Sources must support this.
|
||||
|
||||
Reference in New Issue
Block a user