mirror of
https://github.com/soukoku/ntwain.git
synced 2026-01-02 04:17:08 +08:00
Try to use twaindsm by default.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using NTwain.Data;
|
||||
using NTwain.Values;
|
||||
using System.IO;
|
||||
|
||||
namespace NTwain.Triplets
|
||||
{
|
||||
@@ -19,9 +20,16 @@ namespace NTwain.Triplets
|
||||
// A proper 64 bit twain driver would've installed it so
|
||||
// in essence it only exists in 64 bit systems and thus
|
||||
// the 2 sets of identical pinvokes :(
|
||||
// There's another way of doing own pinvoke at runtime but
|
||||
// that's not easy to understand.
|
||||
public static readonly bool Is64Bit = IntPtr.Size == 8;
|
||||
|
||||
public static readonly bool CanUseTwainDSM = CheckIfCanUseNewDSM();
|
||||
|
||||
private static bool CheckIfCanUseNewDSM()
|
||||
{
|
||||
var path = Path.Combine(Environment.SystemDirectory, "twaindsm.dll");
|
||||
// if 64bit or the dll exists use it
|
||||
return IntPtr.Size == 8 ||
|
||||
File.Exists(path);
|
||||
}
|
||||
|
||||
// define sig for each different data type since "object" doesn't work
|
||||
|
||||
@@ -35,7 +43,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
ref IntPtr data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, dg, dat, msg, ref data); }
|
||||
}
|
||||
|
||||
@@ -47,7 +55,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
ref uint data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, dg, dat, msg, ref data); }
|
||||
}
|
||||
|
||||
@@ -57,7 +65,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWAudioInfo data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Audio, DataArgumentType.AudioInfo, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Audio, DataArgumentType.AudioInfo, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Audio, DataArgumentType.AudioInfo, msg, data); }
|
||||
}
|
||||
|
||||
@@ -68,7 +76,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWCapability data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
|
||||
}
|
||||
|
||||
@@ -79,7 +87,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWCustomDSData data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.CustomDSData, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.CustomDSData, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.CustomDSData, msg, data); }
|
||||
}
|
||||
|
||||
@@ -90,7 +98,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWDeviceEvent data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.DeviceEvent, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.DeviceEvent, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.DeviceEvent, msg, data); }
|
||||
}
|
||||
|
||||
@@ -101,7 +109,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWCallback data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
}
|
||||
|
||||
@@ -112,7 +120,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWCallback2 data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
}
|
||||
|
||||
@@ -123,7 +131,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWEntryPoint data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.EntryPoint, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.EntryPoint, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.EntryPoint, msg, data); }
|
||||
}
|
||||
|
||||
@@ -134,7 +142,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWEvent data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data); }
|
||||
}
|
||||
|
||||
@@ -145,7 +153,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWFileSystem data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.FileSystem, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.FileSystem, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.FileSystem, msg, data); }
|
||||
}
|
||||
|
||||
@@ -154,7 +162,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWIdentity data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, data); }
|
||||
}
|
||||
|
||||
@@ -165,7 +173,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWPassThru data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.PassThru, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.PassThru, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.PassThru, msg, data); }
|
||||
}
|
||||
|
||||
@@ -176,7 +184,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWPendingXfers data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.PendingXfers, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.PendingXfers, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.PendingXfers, msg, data); }
|
||||
}
|
||||
|
||||
@@ -187,7 +195,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWSetupFileXfer data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, data); }
|
||||
}
|
||||
|
||||
@@ -198,7 +206,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWSetupMemXfer data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.SetupMemXfer, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.SetupMemXfer, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.SetupMemXfer, msg, data); }
|
||||
}
|
||||
|
||||
@@ -209,7 +217,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWStatusUtf8 data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.StatusUtf8, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.StatusUtf8, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.StatusUtf8, msg, data); }
|
||||
}
|
||||
|
||||
@@ -220,7 +228,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWUserInterface data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.UserInterface, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.UserInterface, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.UserInterface, msg, data); }
|
||||
}
|
||||
|
||||
@@ -231,7 +239,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWCieColor data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.CieColor, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.CieColor, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.CieColor, msg, data); }
|
||||
}
|
||||
|
||||
@@ -242,7 +250,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWExtImageInfo data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ExtImageInfo, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ExtImageInfo, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ExtImageInfo, msg, data); }
|
||||
}
|
||||
|
||||
@@ -252,7 +260,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWFilter data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.Filter, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.Filter, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.Filter, msg, data); }
|
||||
}
|
||||
|
||||
@@ -262,7 +270,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWGrayResponse data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.GrayResponse, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.GrayResponse, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.GrayResponse, msg, data); }
|
||||
}
|
||||
|
||||
@@ -273,7 +281,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWImageInfo data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data); }
|
||||
}
|
||||
|
||||
@@ -284,7 +292,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWImageLayout data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageLayout, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageLayout, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ImageLayout, msg, data); }
|
||||
}
|
||||
|
||||
@@ -295,7 +303,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWImageMemXfer data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageMemXfer, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageMemXfer, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ImageMemXfer, msg, data); }
|
||||
}
|
||||
|
||||
@@ -306,7 +314,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWJpegCompression data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.JpegCompression, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.JpegCompression, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.JpegCompression, msg, data); }
|
||||
}
|
||||
|
||||
@@ -317,7 +325,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWPalette8 data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.Palette8, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.Palette8, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.Palette8, msg, data); }
|
||||
}
|
||||
|
||||
@@ -328,7 +336,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWRgbResponse data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.RgbResponse, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.RgbResponse, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.RgbResponse, msg, data); }
|
||||
}
|
||||
|
||||
@@ -339,7 +347,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
TWStatus data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Status, msg, data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Status, msg, data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Status, msg, data); }
|
||||
}
|
||||
|
||||
@@ -351,7 +359,7 @@ namespace NTwain.Triplets
|
||||
Message msg,
|
||||
ref TWMemory data)
|
||||
{
|
||||
if (Is64Bit) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, dat, msg, ref data); }
|
||||
if (CanUseTwainDSM) { return WinNativeMethods.DsmEntry64(origin, destination, DataGroups.Control, dat, msg, ref data); }
|
||||
else { return WinNativeMethods.DsmEntry32(origin, destination, DataGroups.Control, dat, msg, ref data); }
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
|
||||
Reference in New Issue
Block a user