Added cap value writer placeholders.

This commit is contained in:
Eugene Wang 2021-04-25 19:45:48 -04:00
parent 34c395db09
commit f91620cdf5
2 changed files with 150 additions and 1 deletions

View File

@ -185,6 +185,120 @@ namespace NTwain
var sts = _twain.DatCapability(DG.CONTROL, MSG.RESET, ref twCap);
return sts;
}
}
/// <summary>
/// Try to set a one value for the cap.
/// </summary>
/// <param name="setMsg"></param>
/// <param name="value"></param>
/// <returns></returns>
public STS SetOrConstraint(MSG setMsg, TValue value)
{
if (setMsg != MSG.SET && setMsg != MSG.SETCONSTRAINT)
throw new ArgumentException($"Only {nameof(MSG.SET)} and {nameof(MSG.SETCONSTRAINT)} messages are supported.", nameof(setMsg));
var twCap = new TW_CAPABILITY
{
Cap = Cap,
ConType = TWON.ONEVALUE
};
try
{
ValueWriter.WriteOneValue(_twain, twCap, value);
return _twain.DatCapability(DG.CONTROL, setMsg, ref twCap);
}
finally
{
if (twCap.hContainer != IntPtr.Zero)
_twain.DsmMemFree(ref twCap.hContainer);
}
}
/// <summary>
/// Try to set an array value for the cap.
/// </summary>
/// <param name="setMsg"></param>
/// <param name="values"></param>
/// <returns></returns>
public STS SetOrConstraint(MSG setMsg, TValue[] values)
{
if (setMsg != MSG.SET && setMsg != MSG.SETCONSTRAINT)
throw new ArgumentException($"Only {nameof(MSG.SET)} and {nameof(MSG.SETCONSTRAINT)} messages are supported.", nameof(setMsg));
if (values == null) throw new ArgumentNullException(nameof(values));
var twCap = new TW_CAPABILITY
{
Cap = Cap,
ConType = TWON.ARRAY
};
try
{
ValueWriter.WriteArray(_twain, twCap, values);
return _twain.DatCapability(DG.CONTROL, setMsg, ref twCap);
}
finally
{
if (twCap.hContainer != IntPtr.Zero)
_twain.DsmMemFree(ref twCap.hContainer);
}
}
/// <summary>
/// Try to set a range value for the cap.
/// </summary>
/// <param name="setMsg"></param>
/// <param name="value"></param>
/// <returns></returns>
public STS SetOrConstraint(MSG setMsg, Range<TValue> value)
{
if (setMsg != MSG.SET && setMsg != MSG.SETCONSTRAINT)
throw new ArgumentException($"Only {nameof(MSG.SET)} and {nameof(MSG.SETCONSTRAINT)} messages are supported.", nameof(setMsg));
if (value == null) throw new ArgumentNullException(nameof(value));
var twCap = new TW_CAPABILITY
{
Cap = Cap,
ConType = TWON.RANGE
};
try
{
ValueWriter.WriteRange(_twain, twCap, value);
return _twain.DatCapability(DG.CONTROL, setMsg, ref twCap);
}
finally
{
if (twCap.hContainer != IntPtr.Zero)
_twain.DsmMemFree(ref twCap.hContainer);
}
}
/// <summary>
/// Try to set an array value for the cap.
/// </summary>
/// <param name="setMsg"></param>
/// <param name="value"></param>
/// <returns></returns>
public STS SetOrConstraint(MSG setMsg, Enumeration<TValue> value)
{
if (setMsg != MSG.SET && setMsg != MSG.SETCONSTRAINT)
throw new ArgumentException($"Only {nameof(MSG.SET)} and {nameof(MSG.SETCONSTRAINT)} messages are supported.", nameof(setMsg));
if (value == null) throw new ArgumentNullException(nameof(value));
var twCap = new TW_CAPABILITY
{
Cap = Cap,
ConType = TWON.ENUMERATION
};
try
{
ValueWriter.WriteEnum(_twain, twCap, value);
return _twain.DatCapability(DG.CONTROL, setMsg, ref twCap);
}
finally
{
if (twCap.hContainer != IntPtr.Zero)
_twain.DsmMemFree(ref twCap.hContainer);
}
}
}
}

35
src/NTwain/ValueWriter.cs Normal file
View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TWAINWorkingGroup;
namespace NTwain
{
/// <summary>
/// Contains methods for writing vairous things to pointers.
/// </summary>
public static class ValueWriter
{
public static void WriteOneValue<TValue>(TWAIN twain, TW_CAPABILITY twCap, TValue value) where TValue : struct
{
throw new NotImplementedException();
}
public static void WriteArray<TValue>(TWAIN twain, TW_CAPABILITY twCap, TValue[] values) where TValue : struct
{
throw new NotImplementedException();
}
public static void WriteRange<TValue>(TWAIN twain, TW_CAPABILITY twCap, Range<TValue> value) where TValue : struct
{
throw new NotImplementedException();
}
public static void WriteEnum<TValue>(TWAIN twain, TW_CAPABILITY twCap, Enumeration<TValue> value) where TValue : struct
{
throw new NotImplementedException();
}
}
}