Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TwCapability"/> class.
        /// </summary>
        /// <param name="cap">The cap.</param>
        /// <param name="range">The range.</param>
        public TwCapability(TwCap cap, _TwRange range)
        {
            this.Cap     = cap;
            this.ConType = TwOn.Range;
            this.Handle  = Twain32.GlobalAlloc(0x42, Marshal.SizeOf(typeof(_TwRange)));
            IntPtr _pTwRange = Twain32.GlobalLock(Handle);

            Marshal.StructureToPtr(range, _pTwRange, true);
            Twain32.GlobalUnlock(Handle);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TwCapability"/> class.
        /// </summary>
        /// <param name="cap">The cap.</param>
        /// <param name="enumeration">The enumeration.</param>
        /// <param name="enumerationValue">The enumeration value.</param>
        public TwCapability(TwCap cap, _TwEnumeration enumeration, object[] enumerationValue)
        {
            this.Cap     = cap;
            this.ConType = TwOn.Enum;
            this.Handle  = Twain32.GlobalAlloc(0x42, Marshal.SizeOf(typeof(_TwEnumeration)) + (Marshal.SizeOf(enumerationValue[0]) * enumerationValue.Length));
            IntPtr _pTwEnumeration = Twain32.GlobalLock(Handle);

            Marshal.StructureToPtr(enumeration, _pTwEnumeration, true);
            for (int i = 0, _ptr = _pTwEnumeration.ToInt32() + Marshal.SizeOf(typeof(_TwEnumeration)); i < enumerationValue.Length; i++, _ptr += Marshal.SizeOf(enumerationValue[0]))
            {
                Marshal.StructureToPtr(enumerationValue[i], (IntPtr)_ptr, true);
            }
            Twain32.GlobalUnlock(Handle);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TwCapability"/> class.
        /// </summary>
        /// <param name="cap">The cap.</param>
        /// <param name="array">The array.</param>
        /// <param name="arrayValue">The array value.</param>
        public TwCapability(TwCap cap, _TwArray array, object[] arrayValue)
        {
            this.Cap     = cap;
            this.ConType = TwOn.Array;
            this.Handle  = Twain32.GlobalAlloc(0x42, Marshal.SizeOf(typeof(_TwArray)) + (Marshal.SizeOf(arrayValue[0]) * arrayValue.Length));
            IntPtr _pTwArray = Twain32.GlobalLock(Handle);

            Marshal.StructureToPtr(array, _pTwArray, true);
            for (int i = 0, _ptr = _pTwArray.ToInt32() + Marshal.SizeOf(typeof(_TwArray)); i < arrayValue.Length; i++, _ptr += Marshal.SizeOf(arrayValue[0]))
            {
                Marshal.StructureToPtr(arrayValue[i], (IntPtr)_ptr, true);
            }
            Twain32.GlobalUnlock(Handle);
        }
        private TwCapability _ToTwCapability(object[] data, TwOn container)
        {
            switch (container)
            {
            case TwOn.One:
                if (data[0] is string)
                {
                    return(new TwCapability(this.CapabilityInfo.Capability, data[0] as string, this.CapabilityInfo.Type));
                }
                else
                {
                    return(new TwCapability(this.CapabilityInfo.Capability, TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[0])), this.CapabilityInfo.Type));
                }

            case TwOn.Range:     //object[] {<MinValue>,<StepSize>,<DefaultValue>,<CurrentValue>,<MaxValue>}
                return(new TwCapability(
                           this.CapabilityInfo.Capability,
                           new TwRange {
                    ItemType = this.CapabilityInfo.Type,
                    DefaultValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[2])),
                    CurrentValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[3])),
                    MinValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[0])),
                    MaxValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[data.Length - 1])),
                    StepSize = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[1]))
                }));

            case TwOn.Array:
                return(new TwCapability(
                           this.CapabilityInfo.Capability,
                           new TwArray {
                    ItemType = this.CapabilityInfo.Type,
                    NumItems = (uint)data.Length
                },
                           data));

            case TwOn.Enum:
                return(new TwCapability(
                           this.CapabilityInfo.Capability,
                           new TwEnumeration {
                    ItemType = this.CapabilityInfo.Type,
                    NumItems = (uint)data.Length,
                    DefaultIndex = (uint)this.DefaultIndex,
                    CurrentIndex = (uint)this.CurrentIndex
                },
                           data));
            }
            throw new DataSourceException(TwRC.Failure, TwCC.CapSeqError);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TwCapability"/> class.
        /// </summary>
        /// <param name="cap">The cap.</param>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        public TwCapability(TwCap cap, int value, TwType type)
        {
            this.Cap     = cap;
            this.ConType = TwOn.One;
            _TwOneValue _value = new _TwOneValue()
            {
                ItemType = type,
                Item     = value
            };

            this.Handle = Twain32.GlobalAlloc(0x42, Marshal.SizeOf(typeof(_TwOneValue)));
            IntPtr _pTwOneValue = Twain32.GlobalLock(Handle);

            Marshal.StructureToPtr(_value, _pTwOneValue, true);
            Twain32.GlobalUnlock(Handle);
        }
      public TwCapability(TwCap cap, TwType valueType, object value)
      {
        CapabilityType = cap;
        ContainerType = TwOn.One;

        value = CastFromCapabilityType(value);

        TwOneValue container = new TwOneValue(valueType, value);

        Handle = LibKernel32.GlobalAlloc(0x42, Marshal.SizeOf(container));

        try
        {
          IntPtr pv = LibKernel32.GlobalLock(Handle);
          Marshal.StructureToPtr(container, pv, true);
        }
        finally
        {
          LibKernel32.GlobalUnlock(Handle);
        }
      }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwCapability"/> class.
 /// </summary>
 /// <param name="cap">The cap.</param>
 public TwCapability(TwCap cap)
 {
     this.Cap     = cap;
     this.ConType = TwOn.DontCare;
 }
 public IntPtr contentValuePtr; //数据类型所指向的句柄
 public TwCapability(TwCap capID)
 {
     this.capID           = capID;
     this.contentType     = TwOn.DontCare;
     this.contentValuePtr = IntPtr.Zero;
 }