More progress.

This commit is contained in:
soukoku 2014-04-05 18:33:21 -04:00
parent 26dd1e7568
commit 94f2720de4
43 changed files with 438 additions and 161 deletions

View File

@ -665,7 +665,7 @@ namespace NTwain.Data
var value = new TWOneValue();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
try
{
int offset = 0;
@ -674,7 +674,7 @@ namespace NTwain.Data
value.Item = (uint)ReadValue(baseAddr, ref offset, ItemType.UInt32);
}
catch { }
MemoryManager.Instance.MemUnlock(_hContainer);
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
@ -688,7 +688,7 @@ namespace NTwain.Data
// since one value can only house UInt32 we will not allow type size > 4
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid one value type"); }
_hContainer = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(value));
_hContainer = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(value));
if (_hContainer != IntPtr.Zero)
{
Marshal.StructureToPtr(value, _hContainer, false);
@ -707,7 +707,7 @@ namespace NTwain.Data
var value = new TWArray();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
@ -721,7 +721,7 @@ namespace NTwain.Data
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
}
}
MemoryManager.Instance.MemUnlock(_hContainer);
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
@ -738,7 +738,7 @@ namespace NTwain.Data
var value = new TWEnumeration();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
@ -756,7 +756,7 @@ namespace NTwain.Data
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
}
}
MemoryManager.Instance.MemUnlock(_hContainer);
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
@ -770,8 +770,8 @@ namespace NTwain.Data
Int32 valueSize = value.ItemOffset + value.ItemList.Length * GetItemTypeSize(value.ItemType);
int offset = 0;
_hContainer = MemoryManager.Instance.MemAllocate((uint)valueSize);
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
_hContainer = MemoryManager.Instance.Allocate((uint)valueSize);
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
// can't safely use StructureToPtr here so write it our own
WriteValue(baseAddr, ref offset, ItemType.UInt16, value.ItemType);
@ -782,7 +782,7 @@ namespace NTwain.Data
{
WriteValue(baseAddr, ref offset, value.ItemType, item);
}
MemoryManager.Instance.MemUnlock(_hContainer);
MemoryManager.Instance.Unlock(_hContainer);
}
/// <summary>
@ -797,7 +797,7 @@ namespace NTwain.Data
var value = new TWRange();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
@ -812,7 +812,7 @@ namespace NTwain.Data
offset += 4;
value.CurrentValue = (uint)Marshal.ReadInt32(baseAddr, offset);
MemoryManager.Instance.MemUnlock(_hContainer);
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
@ -825,7 +825,7 @@ namespace NTwain.Data
// since range value can only house UInt32 we will not allow type size > 4
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid range value type"); }
_hContainer = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(value));
_hContainer = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(value));
if (_hContainer != IntPtr.Zero)
{
Marshal.StructureToPtr(value, _hContainer, false);
@ -1125,7 +1125,7 @@ namespace NTwain.Data
{
if (_hContainer != IntPtr.Zero)
{
MemoryManager.Instance.MemFree(_hContainer);
MemoryManager.Instance.Free(_hContainer);
_hContainer = IntPtr.Zero;
}
GC.SuppressFinalize(this);
@ -1138,7 +1138,7 @@ namespace NTwain.Data
{
if (_hContainer != IntPtr.Zero)
{
MemoryManager.Instance.MemFree(_hContainer);
MemoryManager.Instance.Free(_hContainer);
_hContainer = IntPtr.Zero;
}
}

View File

@ -7,29 +7,29 @@ namespace NTwain
public interface IMemoryManager
{
/// <summary>
/// Function to allocate memory. Calls to this must be coupled with <see cref="MemFree"/> later.
/// Function to allocate memory. Calls to this must be coupled with <see cref="Free"/> later.
/// </summary>
/// <param name="size">The size in bytes.</param>
/// <returns>Handle to the allocated memory.</returns>
IntPtr MemAllocate(uint size);
IntPtr Allocate(uint size);
/// <summary>
/// Function to free memory.
/// </summary>
/// <param name="handle">The handle from <see cref="MemAllocate"/>.</param>
void MemFree(IntPtr handle);
/// <param name="handle">The handle from <see cref="Allocate"/>.</param>
void Free(IntPtr handle);
/// <summary>
/// Function to lock some memory. Calls to this must be coupled with <see cref="MemUnlock"/> later.
/// Function to lock some memory. Calls to this must be coupled with <see cref="Unlock"/> later.
/// </summary>
/// <param name="handle">The handle to allocated memory.</param>
/// <returns>Handle to the lock.</returns>
IntPtr MemLock(IntPtr handle);
IntPtr Lock(IntPtr handle);
/// <summary>
/// Function to unlock a previously locked memory region.
/// </summary>
/// <param name="handle">The handle from <see cref="MemLock"/>.</param>
void MemUnlock(IntPtr handle);
/// <param name="handle">The handle from <see cref="Lock"/>.</param>
void Unlock(IntPtr handle);
}
}

View File

@ -8,13 +8,7 @@ namespace NTwain
/// Interface for keeping track of current TWAIN state with current app and source ids.
/// </summary>
public interface ITwainState : INotifyPropertyChanged
{
/// <summary>
/// Gets the app id used for the session.
/// </summary>
/// <value>The app id.</value>
TWIdentity AppId { get; }
{
/// <summary>
/// Gets the source id used for the session.
/// </summary>
@ -34,6 +28,12 @@ namespace NTwain
/// </summary>
interface ITwainStateInternal : ITwainState
{
/// <summary>
/// Gets the app id used for the session.
/// </summary>
/// <returns></returns>
TWIdentity GetAppId();
/// <summary>
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
/// </summary>

View File

@ -32,11 +32,11 @@ namespace NTwain
TWEntryPoint _twain2Entry;
/// <summary>
/// Function to allocate memory. Calls to this must be coupled with <see cref="MemFree"/> later.
/// Function to allocate memory. Calls to this must be coupled with <see cref="Free"/> later.
/// </summary>
/// <param name="size">The size in bytes.</param>
/// <returns>Handle to the allocated memory.</returns>
public IntPtr MemAllocate(uint size)
public IntPtr Allocate(uint size)
{
if (_twain2Entry != null && _twain2Entry.AllocateFunction != null)
{
@ -52,8 +52,8 @@ namespace NTwain
/// <summary>
/// Function to free memory.
/// </summary>
/// <param name="handle">The handle from <see cref="MemAllocate"/>.</param>
public void MemFree(IntPtr handle)
/// <param name="handle">The handle from <see cref="Allocate"/>.</param>
public void Free(IntPtr handle)
{
if (_twain2Entry != null && _twain2Entry.FreeFunction != null)
{
@ -66,11 +66,11 @@ namespace NTwain
}
/// <summary>
/// Function to lock some memory. Calls to this must be coupled with <see cref="MemUnlock"/> later.
/// Function to lock some memory. Calls to this must be coupled with <see cref="Unlock"/> later.
/// </summary>
/// <param name="handle">The handle to allocated memory.</param>
/// <returns>Handle to the lock.</returns>
public IntPtr MemLock(IntPtr handle)
public IntPtr Lock(IntPtr handle)
{
if (_twain2Entry != null && _twain2Entry.LockFunction != null)
{
@ -85,8 +85,8 @@ namespace NTwain
/// <summary>
/// Function to unlock a previously locked memory region.
/// </summary>
/// <param name="handle">The handle from <see cref="MemLock"/>.</param>
public void MemUnlock(IntPtr handle)
/// <param name="handle">The handle from <see cref="Lock"/>.</param>
public void Unlock(IntPtr handle)
{
if (_twain2Entry != null && _twain2Entry.UnlockFunction != null)
{

View File

@ -18,7 +18,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(6, 6, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get);
IntPtr z = IntPtr.Zero;
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get, ref z);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Audio, DataArgumentType.AudioFileXfer, Message.Get, ref z);
}
}
}

View File

@ -18,7 +18,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(6, 7, DataGroups.Audio, DataArgumentType.AudioInfo, Message.Get);
info = new TWAudioInfo();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, info);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, info);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
public ReturnCode Get(ref IntPtr handle)
{
Session.VerifyState(6, 6, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get, ref handle);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Audio, DataArgumentType.AudioNativeXfer, Message.Get, ref handle);
}
}
}

View File

@ -17,7 +17,7 @@ namespace NTwain.Triplets
public ReturnCode RegisterCallback(TWCallback callback)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Callback, Message.RegisterCallback);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.RegisterCallback, callback);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.RegisterCallback, callback);
}
}
}

View File

@ -17,7 +17,7 @@ namespace NTwain.Triplets
public ReturnCode RegisterCallback(TWCallback2 callback)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Callback, Message.RegisterCallback);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.RegisterCallback, callback);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.RegisterCallback, callback);
}
}
}

View File

@ -18,7 +18,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, capability);
}
/// <summary>
@ -29,7 +29,7 @@ namespace NTwain.Triplets
public ReturnCode GetCurrent(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.GetCurrent);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetCurrent, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetCurrent, capability);
}
/// <summary>
@ -40,7 +40,7 @@ namespace NTwain.Triplets
public ReturnCode GetDefault(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.GetDefault);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetDefault, capability);
}
/// <summary>
@ -52,7 +52,7 @@ namespace NTwain.Triplets
public ReturnCode GetHelp(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.GetHelp);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetHelp, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetHelp, capability);
}
/// <summary>
@ -64,7 +64,7 @@ namespace NTwain.Triplets
public ReturnCode GetLabel(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.GetLabel);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetLabel, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetLabel, capability);
}
/// <summary>
@ -76,7 +76,7 @@ namespace NTwain.Triplets
public ReturnCode GetLabelEnum(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.GetLabelEnum);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetLabelEnum, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetLabelEnum, capability);
}
/// <summary>
@ -87,7 +87,7 @@ namespace NTwain.Triplets
public ReturnCode QuerySupport(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.QuerySupport);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.QuerySupport, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.QuerySupport, capability);
}
/// <summary>
@ -99,7 +99,7 @@ namespace NTwain.Triplets
public ReturnCode Reset(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.Reset);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, capability);
}
/// <summary>
@ -111,7 +111,7 @@ namespace NTwain.Triplets
public ReturnCode ResetAll(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.ResetAll);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.ResetAll, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.ResetAll, capability);
}
/// <summary>
@ -126,7 +126,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWCapability capability)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.Capability, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, capability);
}
/// <summary>
@ -140,7 +140,7 @@ namespace NTwain.Triplets
public ReturnCode SetConstraint(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.SetConstraint);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.SetConstraint, capability);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.SetConstraint, capability);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.CustomDSData, Message.Get);
customData = new TWCustomDSData();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, customData);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, customData);
}
/// <summary>
@ -34,7 +34,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWCustomDSData customData)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.CustomDSData, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, customData);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, customData);
}
}
}

View File

@ -14,7 +14,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get);
sourceDeviceEvent = new TWDeviceEvent();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, sourceDeviceEvent);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, sourceDeviceEvent);
}
}
}

View File

@ -19,7 +19,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(3, 3, DataGroups.Control, DataArgumentType.EntryPoint, Message.Get);
entryPoint = new TWEntryPoint();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, entryPoint);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, entryPoint);
}
}
}

View File

@ -23,7 +23,7 @@ namespace NTwain.Triplets
public ReturnCode ProcessEvent(TWEvent theEvent)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Event, Message.ProcessEvent);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.ProcessEvent, theEvent);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.ProcessEvent, theEvent);
}
}
}

View File

@ -22,7 +22,7 @@ namespace NTwain.Triplets
public ReturnCode AutomaticCaptureDirectory(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.AutomaticCaptureDirectory);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.AutomaticCaptureDirectory, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.AutomaticCaptureDirectory, fileSystem);
}
/// <summary>
@ -37,7 +37,7 @@ namespace NTwain.Triplets
public ReturnCode ChangeDirectory(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.ChangeDirectory);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.ChangeDirectory, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.ChangeDirectory, fileSystem);
}
/// <summary>
@ -53,7 +53,7 @@ namespace NTwain.Triplets
public ReturnCode Copy(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.Copy);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Copy, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Copy, fileSystem);
}
/// <summary>
@ -65,7 +65,7 @@ namespace NTwain.Triplets
public ReturnCode CreateDirectory(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.CreateDirectory);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.CreateDirectory, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.CreateDirectory, fileSystem);
}
/// <summary>
@ -78,7 +78,7 @@ namespace NTwain.Triplets
public ReturnCode Delete(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.Delete);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Delete, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Delete, fileSystem);
}
/// <summary>
@ -90,7 +90,7 @@ namespace NTwain.Triplets
public ReturnCode FormatMedia(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.FormatMedia);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.FormatMedia, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.FormatMedia, fileSystem);
}
/// <summary>
@ -103,7 +103,7 @@ namespace NTwain.Triplets
public ReturnCode GetClose(TWFileSystem fileSystem)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.FileSystem, Message.GetClose);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetClose, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetClose, fileSystem);
}
/// <summary>
@ -115,7 +115,7 @@ namespace NTwain.Triplets
public ReturnCode GetFirstFile(TWFileSystem fileSystem)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.FileSystem, Message.GetFirstFile);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetFirstFile, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetFirstFile, fileSystem);
}
/// <summary>
@ -128,7 +128,7 @@ namespace NTwain.Triplets
public ReturnCode GetInfo(TWFileSystem fileSystem)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.FileSystem, Message.GetInfo);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetInfo, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetInfo, fileSystem);
}
/// <summary>
@ -140,7 +140,7 @@ namespace NTwain.Triplets
public ReturnCode GetNextFile(TWFileSystem fileSystem)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.FileSystem, Message.GetNextFile);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetNextFile, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetNextFile, fileSystem);
}
/// <summary>
@ -156,7 +156,7 @@ namespace NTwain.Triplets
public ReturnCode Rename(TWFileSystem fileSystem)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.FileSystem, Message.Rename);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Rename, fileSystem);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Rename, fileSystem);
}
}
}

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
internal ReturnCode CloseDS()
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Identity, Message.CloseDS);
var rc = PInvoke.DsmEntry(Session.AppId, Message.CloseDS, Session.SourceId);
var rc = PInvoke.DsmEntry(Session.GetAppId(), Message.CloseDS, Session.SourceId);
if (rc == ReturnCode.Success)
{
Session.ChangeSourceId(null);
@ -38,7 +38,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.GetDefault);
source = new TWIdentity();
return PInvoke.DsmEntry(Session.AppId, Message.GetDefault, source);
return PInvoke.DsmEntry(Session.GetAppId(), Message.GetDefault, source);
}
@ -52,7 +52,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.GetFirst);
source = new TWIdentity();
return PInvoke.DsmEntry(Session.AppId, Message.GetFirst, source);
return PInvoke.DsmEntry(Session.GetAppId(), Message.GetFirst, source);
}
/// <summary>
@ -65,7 +65,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.GetNext);
source = new TWIdentity();
return PInvoke.DsmEntry(Session.AppId, Message.GetNext, source);
return PInvoke.DsmEntry(Session.GetAppId(), Message.GetNext, source);
}
/// <summary>
@ -76,7 +76,7 @@ namespace NTwain.Triplets
internal ReturnCode OpenDS(TWIdentity source)
{
Session.VerifyState(3, 3, DataGroups.Control, DataArgumentType.Identity, Message.OpenDS);
var rc = PInvoke.DsmEntry(Session.AppId, Message.OpenDS, source);
var rc = PInvoke.DsmEntry(Session.GetAppId(), Message.OpenDS, source);
if (rc == ReturnCode.Success)
{
Session.ChangeSourceId(source);
@ -95,7 +95,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWIdentity source)
{
Session.VerifyState(3, 3, DataGroups.Control, DataArgumentType.Identity, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Message.Set, source);
return PInvoke.DsmEntry(Session.GetAppId(), Message.Set, source);
}
/// <summary>
@ -108,7 +108,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.UserSelect);
source = new TWIdentity();
return PInvoke.DsmEntry(Session.AppId, Message.UserSelect, source);
return PInvoke.DsmEntry(Session.GetAppId(), Message.UserSelect, source);
}
}
}

View File

@ -20,10 +20,10 @@ namespace NTwain.Triplets
/// <param name="handle">The handle. On Windows = points to the window handle (hWnd) that will act as the Sources
/// "parent". On Macintosh = should be a NULL value.</param>
/// <returns></returns>
public ReturnCode CloseDsm(ref IntPtr handle)
public ReturnCode CloseDsm(IntPtr handle)
{
Session.VerifyState(3, 3, DataGroups.Control, DataArgumentType.Parent, Message.CloseDsm);
var rc = PInvoke.DsmEntry(Session.AppId, null, DataGroups.Control, DataArgumentType.Parent, Message.CloseDsm, ref handle);
var rc = PInvoke.DsmEntry(Session.GetAppId(), null, DataGroups.Control, DataArgumentType.Parent, Message.CloseDsm, ref handle);
if (rc == ReturnCode.Success)
{
Session.ChangeState(2, true);
@ -38,10 +38,10 @@ namespace NTwain.Triplets
/// <param name="handle">The handle. On Windows = points to the window handle (hWnd) that will act as the Sources
/// "parent". On Macintosh = should be a NULL value.</param>
/// <returns></returns>
public ReturnCode OpenDsm(ref IntPtr handle)
public ReturnCode OpenDsm(IntPtr handle)
{
Session.VerifyState(1, 2, DataGroups.Control, DataArgumentType.Parent, Message.OpenDsm);
var rc = PInvoke.DsmEntry(Session.AppId, null, DataGroups.Control, DataArgumentType.Parent, Message.OpenDsm, ref handle);
var rc = PInvoke.DsmEntry(Session.GetAppId(), null, DataGroups.Control, DataArgumentType.Parent, Message.OpenDsm, ref handle);
if (rc == ReturnCode.Success)
{
Session.ChangeState(3, true);

View File

@ -19,7 +19,7 @@ namespace NTwain.Triplets
public ReturnCode PassThrough(TWPassThru sourcePassThru)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.PassThru, Message.PassThru);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.PassThru, sourcePassThru);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.PassThru, sourcePassThru);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
internal ReturnCode EndXfer(TWPendingXfers pendingXfers)
{
Session.VerifyState(6, 7, DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.EndXfer, pendingXfers);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.EndXfer, pendingXfers);
}
/// <summary>
@ -35,7 +35,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWPendingXfers pendingXfers)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.PendingXfers, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, pendingXfers);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, pendingXfers);
}
/// <summary>
@ -46,7 +46,7 @@ namespace NTwain.Triplets
internal ReturnCode Reset(TWPendingXfers pendingXfers)
{
Session.VerifyState(6, 6, DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, pendingXfers);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, pendingXfers);
}
/// <summary>
@ -58,7 +58,7 @@ namespace NTwain.Triplets
public ReturnCode StopFeeder(TWPendingXfers pendingXfers)
{
Session.VerifyState(6, 6, DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.StopFeeder, pendingXfers);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.StopFeeder, pendingXfers);
}
}
}

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Get);
setupFileXfer = new TWSetupFileXfer();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, setupFileXfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, setupFileXfer);
}
/// <summary>
@ -32,7 +32,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.GetDefault);
setupFileXfer = new TWSetupFileXfer();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, setupFileXfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetDefault, setupFileXfer);
}
/// <summary>
@ -45,7 +45,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Reset);
setupFileXfer = new TWSetupFileXfer();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, setupFileXfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, setupFileXfer);
}
/// <summary>
@ -60,7 +60,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWSetupFileXfer setupFileXfer)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, setupFileXfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, setupFileXfer);
}
}

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupMemXfer, Message.Get);
setupMemXfer = new TWSetupMemXfer();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, setupMemXfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, setupMemXfer);
}
}
}

View File

@ -19,7 +19,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(2, 7, DataGroups.Control, DataArgumentType.Status, Message.Get);
status = new TWStatus();
return PInvoke.DsmEntry(Session.AppId, null, Message.Get, status);
return PInvoke.DsmEntry(Session.GetAppId(), null, Message.Get, status);
}
/// <summary>
@ -31,7 +31,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Status, Message.Get);
status = new TWStatus();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, status);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, status);
}
}
}

View File

@ -19,7 +19,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWStatusUtf8 status)
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get);
return PInvoke.DsmEntry(Session.AppId, null, Message.Get, status);
return PInvoke.DsmEntry(Session.GetAppId(), null, Message.Get, status);
}
}
}

View File

@ -23,7 +23,7 @@ namespace NTwain.Triplets
public ReturnCode DisableDS(TWUserInterface userInterface)
{
Session.VerifyState(5, 5, DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS);
var rc = PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.DisableDS, userInterface);
var rc = PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.DisableDS, userInterface);
if (rc == ReturnCode.Success)
{
Session.ChangeState(4, true);
@ -41,7 +41,7 @@ namespace NTwain.Triplets
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDS);
using (var pending = Session.GetPendingStateChanger(5))
{
var rc = PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.EnableDS, userInterface);
var rc = PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.EnableDS, userInterface);
if (rc == ReturnCode.Success ||
(!userInterface.ShowUI && rc == ReturnCode.CheckStatus))
{
@ -63,7 +63,7 @@ namespace NTwain.Triplets
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly);
using (var pending = Session.GetPendingStateChanger(5))
{
var rc = PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.EnableDSUIOnly, userInterface);
var rc = PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.EnableDSUIOnly, userInterface);
if (rc == ReturnCode.Success)
{
pending.Commit();

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
public ReturnCode Get(ref uint value)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.XferGroup, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
}
/// <summary>
@ -33,7 +33,7 @@ namespace NTwain.Triplets
public ReturnCode Set(uint value)
{
Session.VerifyState(6, 6, DataGroups.Control, DataArgumentType.XferGroup, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.CieColor, Message.Get);
cieColor = new TWCieColor();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, cieColor);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, cieColor);
}
}
}

View File

@ -14,7 +14,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWExtImageInfo info)
{
Session.VerifyState(7, 7, DataGroups.Image, DataArgumentType.ExtImageInfo, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, info);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, info);
}
}
}

View File

@ -22,7 +22,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.Filter, Message.Get);
filter = new TWFilter();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, filter);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, filter);
}
/// <summary>
@ -34,7 +34,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.Filter, Message.GetDefault);
filter = new TWFilter();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, filter);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetDefault, filter);
}
/// <summary>
@ -46,7 +46,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWFilter filter)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.Filter, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, filter);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, filter);
}
/// <summary>
@ -58,7 +58,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.Filter, Message.Reset);
filter = new TWFilter();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, filter);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, filter);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.GrayResponse, Message.Reset);
response = new TWGrayResponse();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, response);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, response);
}
/// <summary>
@ -33,7 +33,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWGrayResponse response)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.GrayResponse, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, response);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, response);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(6, 7, DataGroups.Image, DataArgumentType.IccProfile, Message.Get);
profile = new TWMemory();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.IccProfile, Message.Get, ref profile);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataArgumentType.IccProfile, Message.Get, ref profile);
}
}
}

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(6, 6, DataGroups.Image, DataArgumentType.ImageFileXfer, Message.Get);
IntPtr z = IntPtr.Zero;
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataGroups.Image, DataArgumentType.ImageFileXfer, Message.Get, ref z);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Image, DataArgumentType.ImageFileXfer, Message.Get, ref z);
}
}
}

View File

@ -15,7 +15,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(6, 7, DataGroups.Image, DataArgumentType.ImageInfo, Message.Get);
info = new TWImageInfo();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, info);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, info);
}
}
}

View File

@ -15,27 +15,27 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.ImageLayout, Message.Get);
layout = new TWImageLayout();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, layout);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, layout);
}
public ReturnCode GetDefault(out TWImageLayout layout)
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.ImageLayout, Message.GetDefault);
layout = new TWImageLayout();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, layout);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetDefault, layout);
}
public ReturnCode Reset(out TWImageLayout layout)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.ImageLayout, Message.Reset);
layout = new TWImageLayout();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, layout);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, layout);
}
public ReturnCode Set(TWImageLayout layout)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.ImageLayout, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, layout);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, layout);
}
}
}

View File

@ -17,7 +17,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWImageMemXfer xfer)
{
Session.VerifyState(6, 6, DataGroups.Image, DataArgumentType.ImageMemFileXfer, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, xfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, xfer);
}
}

View File

@ -17,7 +17,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWImageMemXfer xfer)
{
Session.VerifyState(6, 7, DataGroups.Image, DataArgumentType.ImageMemXfer, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, xfer);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, xfer);
}
}
}

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
public ReturnCode Get(ref IntPtr handle)
{
Session.VerifyState(6, 6, DataGroups.Image, DataArgumentType.ImageNativeXfer, Message.Get);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, DataGroups.Image, DataArgumentType.ImageNativeXfer, Message.Get, ref handle);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Image, DataArgumentType.ImageNativeXfer, Message.Get, ref handle);
}
}
}

View File

@ -21,7 +21,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.JpegCompression, Message.Get);
compression = new TWJpegCompression();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, compression);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, compression);
}
/// <summary>
@ -34,7 +34,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.JpegCompression, Message.GetDefault);
compression = new TWJpegCompression();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, compression);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetDefault, compression);
}
/// <summary>
@ -46,7 +46,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.JpegCompression, Message.Reset);
compression = new TWJpegCompression();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, compression);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, compression);
}
/// <summary>
@ -59,7 +59,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWJpegCompression compression)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.JpegCompression, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, compression);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, compression);
}
}
}

View File

@ -20,7 +20,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.Palette8, Message.Get);
palette = new TWPalette8();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Get, palette);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Get, palette);
}
/// <summary>
@ -32,7 +32,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.Palette8, Message.GetDefault);
palette = new TWPalette8();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, palette);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.GetDefault, palette);
}
/// <summary>
@ -45,7 +45,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.Palette8, Message.Reset);
palette = new TWPalette8();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, palette);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, palette);
}
/// <summary>
@ -59,7 +59,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWPalette8 palette)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.Palette8, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, palette);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, palette);
}
}
}

View File

@ -22,7 +22,7 @@ namespace NTwain.Triplets
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.RgbResponse, Message.Reset);
response = new TWRgbResponse();
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, response);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Reset, response);
}
/// <summary>
@ -34,7 +34,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWRgbResponse response)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.RgbResponse, Message.Set);
return PInvoke.DsmEntry(Session.AppId, Session.SourceId, Message.Set, response);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, Message.Set, response);
}
}
}

View File

@ -29,7 +29,7 @@ namespace NTwain
public TwainSession(TWIdentity appId)
{
if (appId == null) { throw new ArgumentNullException("appId"); }
AppId = appId;
_appId = appId;
State = 1;
EnforceState = true;
}
@ -38,13 +38,14 @@ namespace NTwain
object _callbackObj;
SynchronizationContext _syncer;
TWIdentity _appId;
/// <summary>
/// Gets the app id used for the session.
/// </summary>
/// <value>The app id.</value>
public TWIdentity AppId { get; private set; }
TWIdentity ITwainStateInternal.GetAppId() { return _appId; }
/// <summary>
/// Gets the source id used for the session.
@ -177,12 +178,11 @@ namespace NTwain
Debug.WriteLine(string.Format("Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId));
_parentHandle = handle;
var hand = handle.Handle;
var rc = DGControl.Parent.OpenDsm(ref hand);
var rc = DGControl.Parent.OpenDsm(handle.Handle);
if (rc == ReturnCode.Success)
{
// if twain2 then get mem management stuff
if ((AppId.DataFunctionalities & DataFunctionalities.Dsm2) == DataFunctionalities.Dsm2)
if ((_appId.DataFunctionalities & DataFunctionalities.Dsm2) == DataFunctionalities.Dsm2)
{
TWEntryPoint entry;
rc = DGControl.EntryPoint.Get(out entry);
@ -208,8 +208,7 @@ namespace NTwain
{
Debug.WriteLine(string.Format("Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
var hand = _parentHandle.Handle;
var rc = DGControl.Parent.CloseDsm(ref hand);
var rc = DGControl.Parent.CloseDsm(_parentHandle.Handle);
if (rc == ReturnCode.Success)
{
_parentHandle = default(HandleRef);
@ -244,7 +243,6 @@ namespace NTwain
var rc = DGControl.Identity.OpenDS(sourceId);
if (rc == ReturnCode.Success)
{
SourceId = sourceId;
SupportedCaps = this.GetCapabilities();
// TODO: does it work?
@ -253,9 +251,9 @@ namespace NTwain
if (!DisableCallback)
{
// app v2.2 or higher uses callback2
if (AppId.ProtocolMajor >= 2 && AppId.ProtocolMinor >= 2)
if (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2)
{
var cb = new TWCallback2(new CallbackDelegate(CallbackHandler));
var cb = new TWCallback2(CallbackHandler);
var rc2 = DGControl.Callback2.RegisterCallback(cb);
if (rc2 == ReturnCode.Success)
@ -266,7 +264,7 @@ namespace NTwain
}
else
{
var cb = new TWCallback(new CallbackDelegate(CallbackHandler));
var cb = new TWCallback(CallbackHandler);
var rc2 = DGControl.Callback.RegisterCallback(cb);
@ -319,7 +317,6 @@ namespace NTwain
var rc = DGControl.Identity.CloseDS();
if (rc == ReturnCode.Success)
{
SourceId = null;
_callbackObj = null;
SupportedCaps = null;
}
@ -504,7 +501,7 @@ namespace NTwain
{
if (dataPtr != IntPtr.Zero)
{
lockedPtr = MemoryManager.Instance.MemLock(dataPtr);
lockedPtr = MemoryManager.Instance.Lock(dataPtr);
}
dtHand(this, new DataTransferredEventArgs(lockedPtr, file));
}
@ -537,12 +534,12 @@ namespace NTwain
// data here is allocated by source so needs to use shared mem calls
if (lockedPtr != IntPtr.Zero)
{
MemoryManager.Instance.MemUnlock(lockedPtr);
MemoryManager.Instance.Unlock(lockedPtr);
lockedPtr = IntPtr.Zero;
}
if (dataPtr != IntPtr.Zero)
{
MemoryManager.Instance.MemFree(dataPtr);
MemoryManager.Instance.Free(dataPtr);
dataPtr = IntPtr.Zero;
}
}
@ -718,14 +715,14 @@ namespace NTwain
try
{
// no need to lock for marshal alloc
msgPtr = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(winmsg));
msgPtr = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(winmsg));
Marshal.StructureToPtr(winmsg, msgPtr, false);
return HandleLoopMsgEvent(ref msgPtr);
}
finally
{
if (msgPtr != IntPtr.Zero)
MemoryManager.Instance.MemFree(msgPtr);
MemoryManager.Instance.Free(msgPtr);
}
}
return false;
@ -757,14 +754,14 @@ namespace NTwain
try
{
// no need to lock for marshal alloc
msgPtr = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(winmsg));
msgPtr = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(winmsg));
Marshal.StructureToPtr(winmsg, msgPtr, false);
handled = HandleLoopMsgEvent(ref msgPtr);
}
finally
{
if (msgPtr != IntPtr.Zero)
MemoryManager.Instance.MemFree(msgPtr);
MemoryManager.Instance.Free(msgPtr);
}
}
return IntPtr.Zero;

View File

@ -1,13 +1,20 @@
using NTwain.Data;
using NTwain.Triplets;
using NTwain.Values;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace NTwain
{
/// <summary>
/// Base working class for interfacing with TWAIN.
/// </summary>
public class TwainSessionBase : ITwainStateInternal, ITwainOperationInternal
{
/// <summary>
@ -18,14 +25,25 @@ namespace NTwain
public TwainSessionBase(TWIdentity appId)
{
if (appId == null) { throw new ArgumentNullException("appId"); }
AppId = appId;
_appId = appId;
State = 1;
EnforceState = true;
}
TWIdentity _appId;
HandleRef _appHandle;
SynchronizationContext _syncer;
object _callbackObj; // kept around so it doesn't get gc'ed
TWUserInterface _twui;
#region ITwainStateInternal Members
/// <summary>
/// Gets the app id used for the session.
/// </summary>
/// <value>The app id.</value>
TWIdentity ITwainStateInternal.GetAppId() { return _appId; }
/// <summary>
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
/// </summary>
@ -60,14 +78,6 @@ namespace NTwain
#region ITwainState Members
/// <summary>
/// Gets the app id used for the session.
/// </summary>
/// <value>
/// The app id.
/// </value>
public TWIdentity AppId { get; private set; }
/// <summary>
/// Gets the source id used for the session.
/// </summary>
@ -129,10 +139,6 @@ namespace NTwain
#endregion
#region ITwainOperationInternal Members
#endregion
#region INotifyPropertyChanged Members
/// <summary>
@ -152,6 +158,230 @@ namespace NTwain
#endregion
#region privileged calls that causes state change in TWAIN
/// <summary>
/// Opens the data source manager. This must be the first method used
/// before using other TWAIN functions. Calls to this must be followed by <see cref="CloseManager"/> when done.
/// </summary>
/// <param name="appHandle">On Windows = points to the window handle (hWnd) that will act as the Sources
/// "parent". On Macintosh = should be a NULL value.</param>
/// <returns></returns>
public ReturnCode OpenManager(HandleRef appHandle)
{
Debug.WriteLine(string.Format("Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId));
var rc = DGControl.Parent.OpenDsm(appHandle.Handle);
if (rc == ReturnCode.Success)
{
_appHandle = appHandle;
// if twain2 then get memory management functions
if ((_appId.DataFunctionalities & DataFunctionalities.Dsm2) == DataFunctionalities.Dsm2)
{
TWEntryPoint entry;
rc = DGControl.EntryPoint.Get(out entry);
if (rc == ReturnCode.Success)
{
MemoryManager.Instance.UpdateEntryPoint(entry);
Debug.WriteLine("Using TWAIN2 memory functions.");
}
else
{
CloseManager();
}
}
}
return rc;
}
/// <summary>
/// Closes the data source manager.
/// </summary>
/// <returns></returns>
public ReturnCode CloseManager()
{
Debug.WriteLine(string.Format("Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
var rc = DGControl.Parent.CloseDsm(_appHandle.Handle);
if (rc == ReturnCode.Success)
{
_appHandle = default(HandleRef);
}
return rc;
}
/// <summary>
/// Loads the specified source into main memory and causes its initialization.
/// Calls to this must be followed by
/// <see cref="CloseSource" /> when done.
/// </summary>
/// <param name="sourceProductName">Name of the source.</param>
/// <returns></returns>
/// <exception cref="ArgumentException">Source name is required.;sourceProductName</exception>
public ReturnCode OpenSource(string sourceProductName)
{
if (string.IsNullOrEmpty(sourceProductName)) { throw new ArgumentException("Source name is required.", "sourceProductName"); }
Debug.WriteLine(string.Format("Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
var source = new TWIdentity();
source.ProductName = sourceProductName;
var rc = DGControl.Identity.OpenDS(source);
if (rc == ReturnCode.Success)
{
}
return rc;
}
/// <summary>
/// When an application is finished with a Source, it must formally close the session between them
/// using this operation. This is necessary in case the Source only supports connection with a single
/// application (many desktop scanners will behave this way). A Source such as this cannot be
/// accessed by other applications until its current session is terminated
/// </summary>
/// <returns></returns>
public ReturnCode CloseSource()
{
Debug.WriteLine(string.Format("Thread {0}: CloseSource.", Thread.CurrentThread.ManagedThreadId));
var rc = DGControl.Identity.CloseDS();
if (rc == ReturnCode.Success)
{
_callbackObj = null;
}
return rc;
}
/// <summary>
/// Enables the source.
/// </summary>
/// <param name="mode">The mode.</param>
/// <param name="modal">if set to <c>true</c> any driver UI will display as modal.</param>
/// <param name="windowHandle">The window handle if modal.</param>
/// <param name="context">The
/// <see cref="SynchronizationContext" /> that is required for certain operations.
/// It is recommended you call this method in a UI thread and pass in
/// <see cref="SynchronizationContext.Current" />
/// if you do not have a custom one setup.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">context</exception>
public ReturnCode EnableSource(SourceEnableMode mode, bool modal, HandleRef windowHandle, SynchronizationContext context)
{
if (context == null) { throw new ArgumentNullException("context"); }
Debug.WriteLine(string.Format("Thread {0}: EnableSource.", Thread.CurrentThread.ManagedThreadId));
_syncer = context;
// app v2.2 or higher uses callback2
if (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2)
{
var cb = new TWCallback2(CallbackHandler);
var rc2 = DGControl.Callback2.RegisterCallback(cb);
if (rc2 == ReturnCode.Success)
{
Debug.WriteLine("Registered callback2 OK.");
_callbackObj = cb;
}
}
else
{
var cb = new TWCallback(CallbackHandler);
var rc2 = DGControl.Callback.RegisterCallback(cb);
if (rc2 == ReturnCode.Success)
{
Debug.WriteLine("Registered callback OK.");
_callbackObj = cb;
}
}
_twui = new TWUserInterface();
_twui.ShowUI = mode == SourceEnableMode.ShowUI;
_twui.ModalUI = modal;
_twui.hParent = windowHandle.Handle;
if (mode == SourceEnableMode.ShowUIOnly)
{
return DGControl.UserInterface.EnableDSUIOnly(_twui);
}
else
{
return DGControl.UserInterface.EnableDS(_twui);
}
}
/// <summary>
/// Disables the source to end data acquisition.
/// </summary>
/// <returns></returns>
ReturnCode DisableSource()
{
Debug.WriteLine(string.Format("Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId));
var rc = DGControl.UserInterface.DisableDS(_twui);
if (rc == ReturnCode.Success)
{
OnSourceDisabled();
}
return rc;
}
/// <summary>
/// Forces the stepping down of an opened source when things gets out of control.
/// Used when session state and source state become out of sync.
/// </summary>
/// <param name="targetState">State of the target.</param>
public void ForceStepDown(int targetState)
{
Debug.WriteLine(string.Format("Thread {0}: ForceStepDown.", Thread.CurrentThread.ManagedThreadId));
bool origFlag = EnforceState;
EnforceState = false;
// From the twain spec
// Stepping Back Down the States
// DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER → state 7 to 6
// DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET → state 6 to 5
// DG_CONTROL / DAT_USERINTERFACE / MSG_DISABLEDS → state 5 to 4
// DG_CONTROL / DAT_IDENTITY / MSG_CLOSEDS → state 4 to 3
// Ignore the status returns from the calls prior to the one yielding the desired state. For instance, if a
// call during scanning returns TWCC_SEQERROR and the desire is to return to state 5, then use the
// following commands.
// DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER → state 7 to 6
// DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET → state 6 to 5
// Being sure to confirm that DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET returned
// success, the return status from DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER may
// be ignored.
if (targetState < 7)
{
DGControl.PendingXfers.EndXfer(new TWPendingXfers());
}
if (targetState < 6)
{
DGControl.PendingXfers.Reset(new TWPendingXfers());
}
if (targetState < 5)
{
DisableSource();
}
if (targetState < 4)
{
CloseSource();
}
if (targetState < 3)
{
CloseManager();
}
EnforceState = origFlag;
}
#endregion
#region custom events and overridables
/// <summary>
@ -164,6 +394,56 @@ namespace NTwain
/// </summary>
protected virtual void OnSourceIdChanged() { }
/// <summary>
/// Called when source has been disabled (back to state 4).
/// </summary>
protected virtual void OnSourceDisabled() { }
#endregion
#region real TWAIN logic during xfer
void HandleSourceMsg(TWIdentity origin, TWIdentity destination, DataGroups dg, DataArgumentType dat, Message msg, IntPtr data)
{
if (msg != Message.Null)
{
Debug.WriteLine(string.Format("Thread {0}: HandleSourceMsg at state {1} with DG={2} DAT={3} MSG={4}.", Thread.CurrentThread.ManagedThreadId, State, dg, dat, msg));
}
}
ReturnCode CallbackHandler(TWIdentity origin, TWIdentity destination, DataGroups dg, DataArgumentType dat, Message msg, IntPtr data)
{
if (origin != null && SourceId != null && origin.Id == SourceId.Id)
{
Debug.WriteLine(string.Format("Thread {0}: CallbackHandler at state {1} with DG={2} DAT={3} MSG={4}.", Thread.CurrentThread.ManagedThreadId, State, dg, dat, msg));
// spec says we must handle this on the thread that enabled the DS,
// but it's usually already the same thread and doesn't work (failure + seqError) w/o jumping to another thread and back.
// My guess is the DS needs to see the Success return code first before letting transfer happen
// so this is an hack to make it happen.
// TODO: find a better method.
ThreadPool.QueueUserWorkItem(o =>
{
var ctx = o as SynchronizationContext;
if (ctx != null)
{
_syncer.Send(blah =>
{
HandleSourceMsg(origin, destination, dg, dat, msg, data);
}, null);
}
else
{
// no context? better hope for the best!
HandleSourceMsg(origin, destination, dg, dat, msg, data);
}
}, _syncer);
return ReturnCode.Success;
}
return ReturnCode.Failure;
}
#endregion
}

View File

@ -1487,7 +1487,7 @@ namespace NTwain.Values
None = 0,
Dsm2 = 0x10000000,
App2 = 0x20000000,
DS2 = 0x40000000,
Ds2 = 0x40000000,
}
/// <summary>

View File

@ -149,7 +149,7 @@ namespace Tester.Winform
var curBtn = (sender as ToolStripMenuItem);
var src = curBtn.Tag as TWIdentity;
if (_twain.OpenSource(src) == ReturnCode.Success)
if (_twain.OpenSource(src.ProductName) == ReturnCode.Success)
{
curBtn.Checked = true;
btnStartCapture.Enabled = true;