mirror of
https://github.com/soukoku/ntwain.git
synced 2025-12-01 19:04:09 +08:00
Initial move from old twain-in-dotnet.
This commit is contained in:
360
NTwain/Triplets/PInvoke.cs
Normal file
360
NTwain/Triplets/PInvoke.cs
Normal file
@@ -0,0 +1,360 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright (c) 2013 Yin-Chun Wang
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using NTwain.Data;
|
||||
using NTwain.Values;
|
||||
|
||||
namespace NTwain.Triplets
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the full TWAIN entry signatures through pinvoke.
|
||||
/// These are called by all the defined triplets methods in
|
||||
/// this namespace.
|
||||
/// </summary>
|
||||
static partial class PInvoke
|
||||
{
|
||||
// Change pinvoke base on where running in 64bit mode.
|
||||
// Theoretically [DllImport("twaindsm", EntryPoint = "#1")]
|
||||
// works on both 32 and 64 bit
|
||||
// but it's not installed on either system by default.
|
||||
// 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;
|
||||
|
||||
// define sig for each different data type since "object" doesn't work
|
||||
|
||||
#region wrapped calls
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
DataGroups dg,
|
||||
DataArgumentType dat,
|
||||
Message msg,
|
||||
ref IntPtr data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, dg, dat, msg, ref data); }
|
||||
}
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWAudioInfo data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Audio, DataArgumentType.AudioInfo, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Audio, DataArgumentType.AudioInfo, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWCapability data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWCustomDSData data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.CustomDSData, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.CustomDSData, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWDeviceEvent data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.DeviceEvent, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.DeviceEvent, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWCallback data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWCallback2 data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWEntryPoint data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.EntryPoint, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.EntryPoint, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWEvent data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWFileSystem data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.FileSystem, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.FileSystem, msg, data); }
|
||||
}
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
Message msg,
|
||||
TWIdentity data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWPassThru data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.PassThru, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.PassThru, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWPendingXfers data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.PendingXfers, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.PendingXfers, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWSetupFileXfer data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWSetupMemXfer data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.SetupMemXfer, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.SetupMemXfer, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWStatusUtf8 data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.StatusUtf8, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.StatusUtf8, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWUserInterface data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.UserInterface, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.UserInterface, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWCieColor data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.CieColor, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.CieColor, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWExtImageInfo data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ExtImageInfo, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ExtImageInfo, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWGrayResponse data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.GrayResponse, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.GrayResponse, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWImageInfo data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWImageLayout data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageLayout, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ImageLayout, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWImageMemXfer data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.ImageMemXfer, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.ImageMemXfer, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWJpegCompression data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.JpegCompression, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.JpegCompression, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWPalette8 data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.Palette8, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.Palette8, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWRgbResponse data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Image, DataArgumentType.RgbResponse, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Image, DataArgumentType.RgbResponse, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
Message msg,
|
||||
TWStatus data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, DataArgumentType.Status, msg, data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, DataArgumentType.Status, msg, data); }
|
||||
}
|
||||
|
||||
|
||||
public static ReturnCode DsmEntry(
|
||||
TWIdentity origin,
|
||||
TWIdentity destination,
|
||||
DataArgumentType dat,
|
||||
Message msg,
|
||||
ref TWMemory data)
|
||||
{
|
||||
if (Is64Bit) { return NativeMethods.DsmEntry64(origin, destination, DataGroups.Control, dat, msg, ref data); }
|
||||
else { return NativeMethods.DsmEntry32(origin, destination, DataGroups.Control, dat, msg, ref data); }
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user