Added cap query support example.

This commit is contained in:
soukoku
2014-04-20 22:24:05 -04:00
parent a766370930
commit 31f77edb40
11 changed files with 76 additions and 44 deletions

View File

@@ -2037,18 +2037,20 @@ namespace NTwain.Data
/// Bit mask for querying the operation that are supported by the data source on a capability.
/// Corresponds to TWQC_*.
/// </summary>
public static class QuerySupportMask
[Flags]
public enum QuerySupport
{
public const int Get = 0x1;
public const int Set = 0x2;
public const int GetDefault = 0x4;
public const int GetCurrent = 0x8;
public const int Reset = 0x10;
public const int SetConstraint = 0x20;
public const int Constrainable = 0x40;
public const int GetHelp = 0x100;
public const int GetLabel = 0x200;
public const int GetLabelEnum = 0x400;
None = 0,
Get = 0x1,
Set = 0x2,
GetDefault = 0x4,
GetCurrent = 0x8,
Reset = 0x10,
SetConstraint = 0x20,
Constrainable = 0x40,
GetHelp = 0x100,
GetLabel = 0x200,
GetLabelEnum = 0x400
}
/// <summary>

View File

@@ -3,9 +3,6 @@ using System.Collections.Generic;
namespace NTwain.Internals
{
/// <summary>
/// Internal interface for state management.
/// </summary>
interface ITwainSessionInternal : ITwainSession
{
/// <summary>

View File

@@ -1,26 +1,26 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace NTwain.Internals
{
static class NativeMethods
[SuppressUnmanagedCodeSecurity]
static class UnsafeNativeMethods
{
// should be unsafe native methods?
#region mem stuff for twain 1.x
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalAlloc")]
public static extern IntPtr WinGlobalAlloc(uint uFlags, UIntPtr dwBytes);
internal static extern IntPtr WinGlobalAlloc(uint uFlags, UIntPtr dwBytes);
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalFree")]
public static extern IntPtr WinGlobalFree(IntPtr hMem);
internal static extern IntPtr WinGlobalFree(IntPtr hMem);
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalLock")]
public static extern IntPtr WinGlobalLock(IntPtr handle);
internal static extern IntPtr WinGlobalLock(IntPtr handle);
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalUnlock")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool WinGlobalUnlock(IntPtr handle);
internal static extern bool WinGlobalUnlock(IntPtr handle);
#endregion
}

View File

@@ -13,7 +13,7 @@ namespace NTwain
{
public IntPtr Allocate(uint size)
{
IntPtr retVal = NativeMethods.WinGlobalAlloc(0x0040, new UIntPtr(size));
IntPtr retVal = UnsafeNativeMethods.WinGlobalAlloc(0x0040, new UIntPtr(size));
if (retVal == IntPtr.Zero)
{
@@ -24,17 +24,17 @@ namespace NTwain
public void Free(IntPtr handle)
{
NativeMethods.WinGlobalFree(handle);
UnsafeNativeMethods.WinGlobalFree(handle);
}
public IntPtr Lock(IntPtr handle)
{
return NativeMethods.WinGlobalLock(handle);
return UnsafeNativeMethods.WinGlobalLock(handle);
}
public void Unlock(IntPtr handle)
{
NativeMethods.WinGlobalUnlock(handle);
UnsafeNativeMethods.WinGlobalUnlock(handle);
}
}
}

View File

@@ -69,7 +69,7 @@
<Compile Include="ITwainState.cs" />
<Compile Include="Internals\WinMemoryManager.cs" />
<Compile Include="Internals\MessageLoop.cs" />
<Compile Include="Internals\NativeMethods.cs" />
<Compile Include="Internals\UnsafeNativeMethods.cs" />
<Compile Include="Platform.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>

View File

@@ -64,7 +64,7 @@ namespace NTwain
}
static readonly WinMemoryManager _defaultMemManager;
static readonly IMemoryManager _defaultMemManager;
static IMemoryManager _specifiedMemManager;
/// <summary>

View File

@@ -6,8 +6,8 @@ using System.Linq;
namespace NTwain
{
/// <summary>
/// Defines common methods on <see cref="TwainSession"/> using the raw
/// TWAIN triplet api.
/// Defines useful methods on <see cref="TwainSession"/> without having to dive into
/// the raw TWAIN triplet API.
/// </summary>
public static class TwainSessionExtensions
{
@@ -68,6 +68,33 @@ namespace NTwain
#region caps routines
/// <summary>
/// Gets the actual supported operations for a capability.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="capId">The cap identifier.</param>
/// <returns></returns>
public static QuerySupport GetCapSupport(this ITwainOperation session, CapabilityId capId)
{
if (session == null) { throw new ArgumentNullException("session"); }
QuerySupport retVal = QuerySupport.None;
using (TWCapability cap = new TWCapability(capId))
{
var rc = session.DGControl.Capability.QuerySupport(cap);
if (rc == ReturnCode.Success)
{
var read = CapReadOut.ReadValue(cap);
if (read.ContainerType == ContainerType.OneValue)
{
retVal = read.OneValue.ConvertToEnum<QuerySupport>();
}
}
}
return retVal;
}
/// <summary>
/// Gets the current value for a capability.
/// </summary>