예제 #1
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);
        }
예제 #2
0
 internal TwEnumeration(_TwEnumeration data, T[] data2)
 {
     this._data  = data;
     this._data2 = data2;
 }
예제 #3
0
        /// <summary>
        /// Возвращает результат для указаной возможности.
        /// </summary>
        /// <returns>Экземпляр TwArray, TwEnumeration, _TwRange или _TwOneValue.</returns>
        public object GetValue()
        {
            IntPtr _handle = Twain32.GlobalLock(this.Handle);

            try {
                switch (this.ConType)
                {
                case TwOn.Array:
                    _TwArray _res = Marshal.PtrToStructure(_handle, typeof(_TwArray)) as _TwArray;
                    switch (_res.ItemType)
                    {
                    case TwType.Int8:
                    case TwType.UInt8: {
                        byte[] _array = new byte[_res.NumItems];
                        Marshal.Copy((IntPtr)(_handle.ToInt32() + Marshal.SizeOf(typeof(_TwArray))), _array, 0, _array.Length);
                        return(new TwArray <byte>(_res, _array));
                    }

                    case TwType.Int16:
                    case TwType.UInt16:
                    case TwType.Bool: {
                        short[] _array = new short[_res.NumItems];
                        Marshal.Copy((IntPtr)(_handle.ToInt32() + Marshal.SizeOf(typeof(_TwArray))), _array, 0, _array.Length);
                        return(new TwArray <short>(_res, _array));
                    }

                    case TwType.Int32:
                    case TwType.UInt32:
                    case TwType.Fix32: {
                        int[] _array = new int[_res.NumItems];
                        Marshal.Copy((IntPtr)(_handle.ToInt32() + Marshal.SizeOf(typeof(_TwArray))), _array, 0, _array.Length);
                        return(new TwArray <int>(_res, _array));
                    }
                    }
                    break;

                case TwOn.Enum:
                    _TwEnumeration _res2 = Marshal.PtrToStructure(_handle, typeof(_TwEnumeration)) as _TwEnumeration;
                    switch (_res2.ItemType)
                    {
                    case TwType.Int8:
                    case TwType.UInt8: {
                        byte[] _array = new byte[_res2.NumItems];
                        Marshal.Copy((IntPtr)(_handle.ToInt32() + Marshal.SizeOf(typeof(_TwEnumeration))), _array, 0, _array.Length);
                        return(new TwEnumeration <byte>(_res2, _array));
                    }

                    case TwType.Int16:
                    case TwType.UInt16:
                    case TwType.Bool: {
                        short[] _array = new short[_res2.NumItems];
                        Marshal.Copy((IntPtr)(_handle.ToInt32() + Marshal.SizeOf(typeof(_TwEnumeration))), _array, 0, _array.Length);
                        return(new TwEnumeration <short>(_res2, _array));
                    }

                    case TwType.Int32:
                    case TwType.UInt32:
                    case TwType.Fix32: {
                        int[] _array = new int[_res2.NumItems];
                        Marshal.Copy((IntPtr)(_handle.ToInt32() + Marshal.SizeOf(typeof(_TwEnumeration))), _array, 0, _array.Length);
                        return(new TwEnumeration <int>(_res2, _array));
                    }
                    }
                    break;

                case TwOn.Range:
                    return(Marshal.PtrToStructure(_handle, typeof(_TwRange)));

                case TwOn.One:
                    return(Marshal.PtrToStructure(_handle, typeof(_TwOneValue)));
                }
                return(null);
            } finally {
                IntPtr _res2 = Twain32.GlobalFree(_handle);
            }
        }