diff --git a/README.md b/README.md index ba73352..1af6646 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # TWAIN Application-Side Library +Note: This was migrated from [https://bitbucket.org/soukoku/ntwain/](https://bitbucket.org/soukoku/ntwain/) for v4 dev. + ## Info This is a library created to make working with [TWAIN](http://twain.org/) interface possible in dotnet. This project has these features/goals: diff --git a/src/NTwain/Data/TwainTypes.cs b/src/NTwain/Data/TwainTypes.cs index fba5a4f..28cedeb 100644 --- a/src/NTwain/Data/TwainTypes.cs +++ b/src/NTwain/Data/TwainTypes.cs @@ -443,8 +443,8 @@ partial class TWSetupMemXfer [StructLayout(LayoutKind.Sequential, Pack = 2)] partial class TWStatus { - TW_UINT16 _conditionCode; - TW_UINT16 _data; + internal TW_UINT16 _conditionCode; + internal TW_UINT16 _data; } [StructLayout(LayoutKind.Sequential, Pack = 2)] diff --git a/src/NTwain/Data/TwainTypesExtended.cs b/src/NTwain/Data/TwainTypesExtended.cs index 0289c99..a1e5cc7 100644 --- a/src/NTwain/Data/TwainTypesExtended.cs +++ b/src/NTwain/Data/TwainTypesExtended.cs @@ -2301,6 +2301,11 @@ public sealed partial class TWStatusUtf8 : IDisposable public TWStatus Status { get { return new TWStatus(_conditionCode, _data); } + internal set + { + _conditionCode = value._conditionCode; + _data = value._data; + } } /// diff --git a/src/NTwain/DataSource.cs b/src/NTwain/DataSource.cs index 17b183e..d9aff4a 100644 --- a/src/NTwain/DataSource.cs +++ b/src/NTwain/DataSource.cs @@ -88,13 +88,14 @@ public TWStatus GetStatus() return stat; } /// - /// Gets the source status. Only call this at state 4 or higher. + /// Gets the source status string. Only call this at state 4 or higher. /// + /// Status from previous calls. /// - public TWStatusUtf8 GetStatusUtf8() + public TWStatusUtf8 GetStatusUtf8(TWStatus status) { TWStatusUtf8 stat; - _session.DGControl.StatusUtf8.GetSource(out stat); + _session.DGControl.StatusUtf8.GetSource(status, out stat); return stat; } @@ -178,30 +179,27 @@ public byte[] Settings get { byte[] value = null; - if (Capabilities.CapCustomDSData.GetCurrent() == BoolType.True) + + TWCustomDSData data; + if (DGControl.CustomDSData.Get(out data) == ReturnCode.Success && data.InfoLength > 0) { - TWCustomDSData data; - if (DGControl.CustomDSData.Get(out data) == ReturnCode.Success && data.InfoLength > 0) + try { - try - { - value = new byte[data.InfoLength]; - var ptr = PlatformInfo.Current.MemoryManager.Lock(data.hData); - Marshal.Copy(ptr, value, 0, (int)data.InfoLength); - } - finally - { - PlatformInfo.Current.MemoryManager.Unlock(data.hData); - PlatformInfo.Current.MemoryManager.Free(data.hData); - } + value = new byte[data.InfoLength]; + var ptr = PlatformInfo.Current.MemoryManager.Lock(data.hData); + Marshal.Copy(ptr, value, 0, (int)data.InfoLength); + } + finally + { + PlatformInfo.Current.MemoryManager.Unlock(data.hData); + PlatformInfo.Current.MemoryManager.Free(data.hData); } } return value; } set { - if (value != null && value.Length > 0 && - Capabilities.CapCustomDSData.GetCurrent() == BoolType.True) + if (value != null && value.Length > 0) { TWCustomDSData data = new TWCustomDSData { diff --git a/src/NTwain/IDataSource.cs b/src/NTwain/IDataSource.cs index eee29be..c58c4e1 100644 --- a/src/NTwain/IDataSource.cs +++ b/src/NTwain/IDataSource.cs @@ -116,9 +116,10 @@ public interface IDataSource : ITripletControl TWStatus GetStatus(); /// - /// Gets the source status. Only call this at state 4 or higher. + /// Gets the source status string. Only call this at state 4 or higher. /// + /// Status from previous calls. /// - TWStatusUtf8 GetStatusUtf8(); + TWStatusUtf8 GetStatusUtf8(TWStatus status); } } diff --git a/src/NTwain/ITwainSession.cs b/src/NTwain/ITwainSession.cs index a1ec498..54abcfc 100644 --- a/src/NTwain/ITwainSession.cs +++ b/src/NTwain/ITwainSession.cs @@ -168,10 +168,11 @@ public interface ITwainSession : IEnumerable, INotifyPropertyChanged TWStatus GetStatus(); /// - /// Gets the manager status. Only call this at state 3 or higher. + /// Gets the manager status string. Only call this at state 3 or higher. /// + /// Status from previous calls. /// - TWStatusUtf8 GetStatusUtf8(); + TWStatusUtf8 GetStatusUtf8(TWStatus status); /// diff --git a/src/NTwain/Properties/VersionInfo.cs b/src/NTwain/Properties/VersionInfo.cs index d3c0256..b6415e7 100644 --- a/src/NTwain/Properties/VersionInfo.cs +++ b/src/NTwain/Properties/VersionInfo.cs @@ -23,7 +23,7 @@ static class VersionInfo /// /// The build release version number. /// - public const string Build = "3.5.3"; // change this for each nuget release + public const string Build = "3.6.0"; // change this for each nuget release } diff --git a/src/NTwain/Triplets/DGAudio/DGAudio.AudioFileXfer.cs b/src/NTwain/Triplets/DGAudio/DGAudio.AudioFileXfer.cs index b594cf4..161caf5 100644 --- a/src/NTwain/Triplets/DGAudio/DGAudio.AudioFileXfer.cs +++ b/src/NTwain/Triplets/DGAudio/DGAudio.AudioFileXfer.cs @@ -19,7 +19,8 @@ public ReturnCode Get() { Session.VerifyState(6, 6, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get); IntPtr z = IntPtr.Zero; - return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get, ref z); + return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, + DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get, ref z); } } } \ No newline at end of file diff --git a/src/NTwain/Triplets/DGAudio/DGAudio.AudioNativeXfer.cs b/src/NTwain/Triplets/DGAudio/DGAudio.AudioNativeXfer.cs index e562343..4eae74a 100644 --- a/src/NTwain/Triplets/DGAudio/DGAudio.AudioNativeXfer.cs +++ b/src/NTwain/Triplets/DGAudio/DGAudio.AudioNativeXfer.cs @@ -22,7 +22,8 @@ internal AudioNativeXfer(ITwainSessionInternal session) : base(session) { } public ReturnCode Get(ref IntPtr handle) { Session.VerifyState(6, 6, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get); - return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get, ref handle); + return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, + DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get, ref handle); } } } \ No newline at end of file diff --git a/src/NTwain/Triplets/DGControl/DGControl.StatusUtf8.cs b/src/NTwain/Triplets/DGControl/DGControl.StatusUtf8.cs index 372327b..8f1f985 100644 --- a/src/NTwain/Triplets/DGControl/DGControl.StatusUtf8.cs +++ b/src/NTwain/Triplets/DGControl/DGControl.StatusUtf8.cs @@ -16,9 +16,9 @@ internal StatusUtf8(ITwainSessionInternal session) : base(session) { } /// /// The status. /// - public ReturnCode GetManager(out TWStatusUtf8 status) + public ReturnCode GetManager(TWStatus status, out TWStatusUtf8 utf8status) { - status = new TWStatusUtf8(); + utf8status = new TWStatusUtf8 { Status = status }; Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get); return Dsm.DsmEntry(Session.AppId, null, Message.Get, status); } @@ -29,9 +29,9 @@ public ReturnCode GetManager(out TWStatusUtf8 status) /// /// The status. /// - public ReturnCode GetSource(out TWStatusUtf8 status) + public ReturnCode GetSource(TWStatus status, out TWStatusUtf8 utf8status) { - status = new TWStatusUtf8(); + utf8status = new TWStatusUtf8 { Status = status }; Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get); return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, status); } diff --git a/src/NTwain/Triplets/DGCustom.cs b/src/NTwain/Triplets/DGCustom.cs index 1d5d320..1af0101 100644 --- a/src/NTwain/Triplets/DGCustom.cs +++ b/src/NTwain/Triplets/DGCustom.cs @@ -39,6 +39,24 @@ public ReturnCode DsmEntry( return Dsm.DsmEntry(_session.AppId, _session.CurrentSource.Identity, group, dat, message, ref data); } + + /// + /// Direct DSM_Entry call with full arguments for custom values. + /// + /// The group. + /// The dat. + /// The message. + /// The data. + /// + public ReturnCode DsmEntry( + DataGroups group, + DataArgumentType dat, + Message message, + IntPtr data) + { + _session.VerifyState(3, 7, group, dat, message); + return Dsm.DsmEntry(_session.AppId, _session.CurrentSource.Identity, group, dat, message, data); + } // todo: add other data value types? } } diff --git a/src/NTwain/Triplets/Dsm.Linux.cs b/src/NTwain/Triplets/Dsm.Linux.cs index 68b0355..7828f36 100644 --- a/src/NTwain/Triplets/Dsm.Linux.cs +++ b/src/NTwain/Triplets/Dsm.Linux.cs @@ -18,6 +18,15 @@ public static extern ReturnCode DsmLinux( Message msg, ref IntPtr data); + [DllImport(LINUX_DSM_PATH, EntryPoint = DSM_ENTRY)] + public static extern ReturnCode DsmLinux( + [In, Out]TWIdentity origin, + [In, Out]TWIdentity destination, + DataGroups dg, + DataArgumentType dat, + Message msg, + IntPtr data); + [DllImport(LINUX_DSM_PATH, EntryPoint = DSM_ENTRY)] public static extern ReturnCode DsmLinux( [In, Out]TWIdentity origin, diff --git a/src/NTwain/Triplets/Dsm.WinNew.cs b/src/NTwain/Triplets/Dsm.WinNew.cs index 0c87b72..a3adb77 100644 --- a/src/NTwain/Triplets/Dsm.WinNew.cs +++ b/src/NTwain/Triplets/Dsm.WinNew.cs @@ -17,6 +17,15 @@ public static extern ReturnCode DsmWinNew( Message msg, ref IntPtr data); + [DllImport(WIN_NEW_DSM_NAME, EntryPoint = DSM_ENTRY)] + public static extern ReturnCode DsmWinNew( + [In, Out]TWIdentity origin, + [In, Out]TWIdentity destination, + DataGroups dg, + DataArgumentType dat, + Message msg, + IntPtr data); + [DllImport(WIN_NEW_DSM_NAME, EntryPoint = DSM_ENTRY)] public static extern ReturnCode DsmWinNew( [In, Out]TWIdentity origin, diff --git a/src/NTwain/Triplets/Dsm.WinOld.cs b/src/NTwain/Triplets/Dsm.WinOld.cs index fabf125..9ae55b3 100644 --- a/src/NTwain/Triplets/Dsm.WinOld.cs +++ b/src/NTwain/Triplets/Dsm.WinOld.cs @@ -17,6 +17,15 @@ public static extern ReturnCode DsmWinOld( Message msg, ref IntPtr data); + [DllImport(WIN_OLD_DSM_NAME, EntryPoint = DSM_ENTRY)] + public static extern ReturnCode DsmWinOld( + [In, Out]TWIdentity origin, + [In, Out]TWIdentity destination, + DataGroups dg, + DataArgumentType dat, + Message msg, + IntPtr data); + [DllImport(WIN_OLD_DSM_NAME, EntryPoint = DSM_ENTRY)] public static extern ReturnCode DsmWinOld( [In, Out]TWIdentity origin, diff --git a/src/NTwain/Triplets/Dsm.cs b/src/NTwain/Triplets/Dsm.cs index 8425f33..6cc8245 100644 --- a/src/NTwain/Triplets/Dsm.cs +++ b/src/NTwain/Triplets/Dsm.cs @@ -37,6 +37,26 @@ public static ReturnCode DsmEntry( throw new PlatformNotSupportedException(); } + public static ReturnCode DsmEntry( + TWIdentity origin, + TWIdentity destination, + DataGroups dg, + DataArgumentType dat, + Message msg, + IntPtr data) + { + if (PlatformInfo.Current.IsWindows) + { + if (PlatformInfo.Current.UseNewWinDSM) { return NativeMethods.DsmWinNew(origin, destination, dg, dat, msg, data); } + else { return NativeMethods.DsmWinOld(origin, destination, dg, dat, msg, data); } + } + else if (PlatformInfo.Current.IsLinux) + { + return NativeMethods.DsmLinux(origin, destination, dg, dat, msg, data); + } + throw new PlatformNotSupportedException(); + } + public static ReturnCode DsmEntry( TWIdentity origin, TWIdentity destination, @@ -161,12 +181,12 @@ public static ReturnCode DsmEntry( { if (PlatformInfo.Current.IsWindows) { - if (PlatformInfo.Current.UseNewWinDSM) { return NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); } - else { return NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); } + if (PlatformInfo.Current.UseNewWinDSM) { return NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, DataArgumentType.Callback2, msg, data); } + else { return NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, DataArgumentType.Callback2, msg, data); } } else if (PlatformInfo.Current.IsLinux) { - return NativeMethods.DsmLinux(origin, destination, DataGroups.Control, DataArgumentType.Callback, msg, data); + return NativeMethods.DsmLinux(origin, destination, DataGroups.Control, DataArgumentType.Callback2, msg, data); } throw new PlatformNotSupportedException(); } diff --git a/src/NTwain/TwainSession.cs b/src/NTwain/TwainSession.cs index c2d7005..f71af1e 100644 --- a/src/NTwain/TwainSession.cs +++ b/src/NTwain/TwainSession.cs @@ -78,6 +78,17 @@ DataSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId) #region ITwainSession Members + DGCustom _dgCustom; + DGCustom ITripletControl.DGCustom { get { return DGCustom; } } + public DGCustom DGCustom + { + get + { + if (_dgCustom == null) { _dgCustom = new DGCustom(this); } + return _dgCustom; + } + } + /// /// Gets or sets a value indicating whether calls to triplets will verify the current twain session state. /// @@ -362,13 +373,14 @@ public TWStatus GetStatus() } /// - /// Gets the manager status. Only call this at state 3 or higher. + /// Gets the manager status string. Only call this at state 3 or higher. /// + /// Status from previous calls. /// - public TWStatusUtf8 GetStatusUtf8() + public TWStatusUtf8 GetStatusUtf8(TWStatus status) { TWStatusUtf8 stat; - ((ITwainSessionInternal)this).DGControl.StatusUtf8.GetManager(out stat); + ((ITwainSessionInternal)this).DGControl.StatusUtf8.GetManager(status, out stat); return stat; } diff --git a/src/NTwain/TwainSessionInternal.cs b/src/NTwain/TwainSessionInternal.cs index 2d80645..e20876b 100644 --- a/src/NTwain/TwainSessionInternal.cs +++ b/src/NTwain/TwainSessionInternal.cs @@ -138,17 +138,6 @@ protected DGImage DGImage } } - DGCustom _dgCustom; - DGCustom ITripletControl.DGCustom { get { return DGCustom; } } - protected DGCustom DGCustom - { - get - { - if (_dgCustom == null) { _dgCustom = new DGCustom(this); } - return _dgCustom; - } - } - /// /// Enables the source to start transferring.