[DllImport("twain_32.dll", EntryPoint = "#1")]
public static extern TwainResult DsCapability([In, Out] Identity origin, [In] Identity dest, DataGroup dg, DataArgumentType dat, Message msg, [In, Out] TwainCapability capa);
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public class TwainCapability : IDisposable
{
Capabilities _capabilities;
ContainerType _containerType;
IntPtr _handle;
object _value;
protected TwainCapability(Capabilities capabilities, ContainerType containerType, object value)
{
_capabilities = capabilities;
_containerType = containerType;
_value = value;
int size;
if (value == null) { size = 0;} else { size = Marshal.SizeOf(value); }
_handle = Kernel32Native.GlobalAlloc(GlobalAllocFlags.Handle, size);
IntPtr p = Kernel32Native.GlobalLock(_handle);
try
{
if (p.Equals(0)) { Marshal.StructureToPtr(value, p, false); };
}
finally
{
Kernel32Native.GlobalUnlock(_handle);
}
}
~TwainCapability()
{
Dispose(false);
}
public static TwainCapability DCCap(Capabilities capabilities, object value)
{
ContainerType containerType;
containerType = ContainerType.DontCare;
return new TwainCapability(capabilities, containerType, value);
}
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (_handle != IntPtr.Zero)
{
Kernel32Native.GlobalFree(_handle);
}
}
}
public SomeResult ReadBackSomeValue()
{
IntPtr p = Kernel32Native.GlobalLock(_handle);
SomeResult sr = new SomeResult();
try
{
CapabilityEnumValue eval = new CapabilityEnumValue();
Marshal.PtrToStructure(p, eval);
sr.contype = ContainerType.Enum;
sr.value = eval;
return sr;
}
catch
{
try
{
CapabilityRangeValue rval = new CapabilityRangeValue();
Marshal.PtrToStructure(p, rval);
sr.contype = ContainerType.Range;
sr.value = rval;
return sr;
}
catch
{
try
{
CapabilityArrayValue aval = new CapabilityArrayValue();
Marshal.PtrToStructure(p, aval);
sr.contype = ContainerType.Array;
sr.value = aval;
return sr;
}
catch
{
sr.contype = ContainerType.DontCare;
sr.value = null;
return sr;
}
}
}
finally
{
Kernel32Native.GlobalUnlock(_handle);
}
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.