Skip to content

Commit

Permalink
New 3.6 build done in github with fixes for mistakes discovered in v4…
Browse files Browse the repository at this point in the history
… dev.
  • Loading branch information
soukoku committed Nov 30, 2018
1 parent 1515508 commit bbc81da
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 49 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/NTwain/Data/TwainTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 5 additions & 0 deletions src/NTwain/Data/TwainTypesExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/// <summary>
Expand Down
36 changes: 17 additions & 19 deletions src/NTwain/DataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ public TWStatus GetStatus()
return stat;
}
/// <summary>
/// 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.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
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;
}

Expand Down Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions src/NTwain/IDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ public interface IDataSource : ITripletControl
TWStatus GetStatus();

/// <summary>
/// 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.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
TWStatusUtf8 GetStatusUtf8();
TWStatusUtf8 GetStatusUtf8(TWStatus status);
}
}
5 changes: 3 additions & 2 deletions src/NTwain/ITwainSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ public interface ITwainSession : IEnumerable<DataSource>, INotifyPropertyChanged
TWStatus GetStatus();

/// <summary>
/// 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.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
TWStatusUtf8 GetStatusUtf8();
TWStatusUtf8 GetStatusUtf8(TWStatus status);


/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NTwain/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static class VersionInfo
/// <summary>
/// The build release version number.
/// </summary>
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


}
Expand Down
3 changes: 2 additions & 1 deletion src/NTwain/Triplets/DGAudio/DGAudio.AudioFileXfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
3 changes: 2 additions & 1 deletion src/NTwain/Triplets/DGAudio/DGAudio.AudioNativeXfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
8 changes: 4 additions & 4 deletions src/NTwain/Triplets/DGControl/DGControl.StatusUtf8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal StatusUtf8(ITwainSessionInternal session) : base(session) { }
/// </summary>
/// <param name="status">The status.</param>
/// <returns></returns>
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);
}
Expand All @@ -29,9 +29,9 @@ public ReturnCode GetManager(out TWStatusUtf8 status)
/// </summary>
/// <param name="status">The status.</param>
/// <returns></returns>
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);
}
Expand Down
18 changes: 18 additions & 0 deletions src/NTwain/Triplets/DGCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ public ReturnCode DsmEntry(
return Dsm.DsmEntry(_session.AppId, _session.CurrentSource.Identity, group, dat, message, ref data);
}


/// <summary>
/// Direct DSM_Entry call with full arguments for custom values.
/// </summary>
/// <param name="group">The group.</param>
/// <param name="dat">The dat.</param>
/// <param name="message">The message.</param>
/// <param name="data">The data.</param>
/// <returns></returns>
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?
}
}
9 changes: 9 additions & 0 deletions src/NTwain/Triplets/Dsm.Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/NTwain/Triplets/Dsm.WinNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/NTwain/Triplets/Dsm.WinOld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 23 additions & 3 deletions src/NTwain/Triplets/Dsm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
18 changes: 15 additions & 3 deletions src/NTwain/TwainSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/// <summary>
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
/// </summary>
Expand Down Expand Up @@ -362,13 +373,14 @@ public TWStatus GetStatus()
}

/// <summary>
/// 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.
/// </summary>
/// <param name="status">Status from previous calls.</param>
/// <returns></returns>
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;
}

Expand Down
11 changes: 0 additions & 11 deletions src/NTwain/TwainSessionInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


/// <summary>
/// Enables the source to start transferring.
Expand Down

0 comments on commit bbc81da

Please sign in to comment.