mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
#31 Add support for setting non-int onevalue for capability
This commit is contained in:
@@ -643,18 +643,30 @@ namespace NTwain.Data
|
|||||||
/// <param name="capability">The capability.</param>
|
/// <param name="capability">The capability.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public TWCapability(CapabilityId capability, TWOneValue value)
|
public TWCapability(CapabilityId capability, TWOneValue value)
|
||||||
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
|
{
|
||||||
|
Capability = capability;
|
||||||
|
SetOneValue(value, PlatformInfo.Current.MemoryManager);
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TWCapability" /> class.
|
/// Initializes a new instance of the <see cref="TWCapability"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="capability">The capability.</param>
|
/// <param name="capability">The capability.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
/// <param name="memoryManager">The memory manager.</param>
|
/// <param name="type">The type.</param>
|
||||||
public TWCapability(CapabilityId capability, TWOneValue value, IMemoryManager memoryManager)
|
public TWCapability(CapabilityId capability, string value, ItemType type)
|
||||||
{
|
{
|
||||||
Capability = capability;
|
Capability = capability;
|
||||||
SetOneValue(value, memoryManager);
|
SetOneValue(value, type, PlatformInfo.Current.MemoryManager);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TWCapability"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="capability">The capability.</param>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
public TWCapability(CapabilityId capability, TWFrame value)
|
||||||
|
{
|
||||||
|
Capability = capability;
|
||||||
|
SetOneValue(value, PlatformInfo.Current.MemoryManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -663,18 +675,9 @@ namespace NTwain.Data
|
|||||||
/// <param name="capability">The capability.</param>
|
/// <param name="capability">The capability.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public TWCapability(CapabilityId capability, TWEnumeration value)
|
public TWCapability(CapabilityId capability, TWEnumeration value)
|
||||||
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="TWCapability" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="capability">The capability.</param>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <param name="memoryManager">The memory manager.</param>
|
|
||||||
public TWCapability(CapabilityId capability, TWEnumeration value, IMemoryManager memoryManager)
|
|
||||||
{
|
{
|
||||||
Capability = capability;
|
Capability = capability;
|
||||||
SetEnumValue(value, memoryManager);
|
SetEnumValue(value, PlatformInfo.Current.MemoryManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -683,18 +686,9 @@ namespace NTwain.Data
|
|||||||
/// <param name="capability">The capability.</param>
|
/// <param name="capability">The capability.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public TWCapability(CapabilityId capability, TWRange value)
|
public TWCapability(CapabilityId capability, TWRange value)
|
||||||
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="TWCapability" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="capability">The capability.</param>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <param name="memoryManager">The memory manager.</param>
|
|
||||||
public TWCapability(CapabilityId capability, TWRange value, IMemoryManager memoryManager)
|
|
||||||
{
|
{
|
||||||
Capability = capability;
|
Capability = capability;
|
||||||
SetRangeValue(value, memoryManager);
|
SetRangeValue(value, PlatformInfo.Current.MemoryManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -703,18 +697,9 @@ namespace NTwain.Data
|
|||||||
/// <param name="capability">The capability.</param>
|
/// <param name="capability">The capability.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public TWCapability(CapabilityId capability, TWArray value)
|
public TWCapability(CapabilityId capability, TWArray value)
|
||||||
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="TWCapability" /> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="capability">The capability.</param>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <param name="memoryManager">The memory manager.</param>
|
|
||||||
public TWCapability(CapabilityId capability, TWArray value, IMemoryManager memoryManager)
|
|
||||||
{
|
{
|
||||||
Capability = capability;
|
Capability = capability;
|
||||||
SetArrayValue(value, memoryManager);
|
SetArrayValue(value, PlatformInfo.Current.MemoryManager);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -737,6 +722,45 @@ namespace NTwain.Data
|
|||||||
|
|
||||||
#region value functions
|
#region value functions
|
||||||
|
|
||||||
|
void SetOneValue(string value, ItemType type, IMemoryManager memoryManager)
|
||||||
|
{
|
||||||
|
ContainerType = ContainerType.OneValue;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ItemType.String128:
|
||||||
|
case ItemType.String255:
|
||||||
|
case ItemType.String32:
|
||||||
|
case ItemType.String64:
|
||||||
|
|
||||||
|
_hContainer = memoryManager.Allocate((uint)(Marshal.SizeOf(typeof(TWFrame)) + 2));
|
||||||
|
if (_hContainer != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
IntPtr baseAddr = memoryManager.Lock(_hContainer);
|
||||||
|
int offset = 0;
|
||||||
|
baseAddr.WriteValue(ref offset, ItemType.UInt16, type);
|
||||||
|
baseAddr.WriteValue(ref offset, type, value);
|
||||||
|
memoryManager.Unlock(_hContainer);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Type {0} is not valid for string.", type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void SetOneValue(TWFrame value, IMemoryManager memoryManager)
|
||||||
|
{
|
||||||
|
ContainerType = ContainerType.OneValue;
|
||||||
|
|
||||||
|
_hContainer = memoryManager.Allocate((uint)(Marshal.SizeOf(typeof(TWFrame)) + 2));
|
||||||
|
if (_hContainer != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
IntPtr baseAddr = memoryManager.Lock(_hContainer);
|
||||||
|
int offset = 0;
|
||||||
|
baseAddr.WriteValue(ref offset, ItemType.UInt16, ItemType.Frame);
|
||||||
|
baseAddr.WriteValue(ref offset, ItemType.Frame, value);
|
||||||
|
memoryManager.Unlock(_hContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetOneValue(TWOneValue value, IMemoryManager memoryManager)
|
void SetOneValue(TWOneValue value, IMemoryManager memoryManager)
|
||||||
{
|
{
|
||||||
if (value == null) { throw new ArgumentNullException("value"); }
|
if (value == null) { throw new ArgumentNullException("value"); }
|
||||||
@@ -762,6 +786,8 @@ namespace NTwain.Data
|
|||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
_hContainer = memoryManager.Allocate((uint)valueSize);
|
_hContainer = memoryManager.Allocate((uint)valueSize);
|
||||||
|
if (_hContainer != IntPtr.Zero)
|
||||||
|
{
|
||||||
IntPtr baseAddr = memoryManager.Lock(_hContainer);
|
IntPtr baseAddr = memoryManager.Lock(_hContainer);
|
||||||
|
|
||||||
// can't safely use StructureToPtr here so write it our own
|
// can't safely use StructureToPtr here so write it our own
|
||||||
@@ -773,9 +799,9 @@ namespace NTwain.Data
|
|||||||
{
|
{
|
||||||
baseAddr.WriteValue(ref offset, value.ItemType, item);
|
baseAddr.WriteValue(ref offset, value.ItemType, item);
|
||||||
}
|
}
|
||||||
//memoryManager.Unlock(baseAddr);
|
|
||||||
memoryManager.Unlock(_hContainer);
|
memoryManager.Unlock(_hContainer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetRangeValue(TWRange value, IMemoryManager memoryManager)
|
void SetRangeValue(TWRange value, IMemoryManager memoryManager)
|
||||||
{
|
{
|
||||||
@@ -801,6 +827,8 @@ namespace NTwain.Data
|
|||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
_hContainer = memoryManager.Allocate((uint)valueSize);
|
_hContainer = memoryManager.Allocate((uint)valueSize);
|
||||||
|
if (_hContainer != IntPtr.Zero)
|
||||||
|
{
|
||||||
IntPtr baseAddr = memoryManager.Lock(_hContainer);
|
IntPtr baseAddr = memoryManager.Lock(_hContainer);
|
||||||
|
|
||||||
// can't safely use StructureToPtr here so write it our own
|
// can't safely use StructureToPtr here so write it our own
|
||||||
@@ -811,7 +839,7 @@ namespace NTwain.Data
|
|||||||
baseAddr.WriteValue(ref offset, value.ItemType, item);
|
baseAddr.WriteValue(ref offset, value.ItemType, item);
|
||||||
}
|
}
|
||||||
memoryManager.Unlock(_hContainer);
|
memoryManager.Unlock(_hContainer);
|
||||||
//memoryManager.Unlock(baseAddr);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user