示例#1
0
        /// <summary> Constructor based on a Structure. </summary>
        /// <exception cref="ArgumentException"> Thrown when one or more arguments have unsupported or
        ///                                      illegal values. </exception>
        /// <param name="struc_param"> The struc parameter. </param>
        /// <param name="Alloc_param"> The allocate parameter. </param>
        public CStruct(TCustomtype struc_param, AllocatedMode Alloc_param = AllocatedMode.None)
        {
            // Make a copy of the supplied Structure
            Struct = struc_param;

            switch (Alloc_param)
            {
            case AllocatedMode.None:
                Pointer           = IntPtr.Zero;
                Pointer_Allocated = AllocatedMode.None;
                break;

            case AllocatedMode.viaNet:
                // Do we need to allocate some memory to copy this into (unmanaged)
                MemoryAllocate();
                CopyStructToPtr();
                break;

            case AllocatedMode.viaDll:
                throw new ArgumentException("AllocatedMode = viaDll not supported in this context");

            case AllocatedMode.Nested:
                throw new ArgumentException("AllocatedMode = Nested not supported in this context");

            default:
                throw new ArgumentOutOfRangeException(nameof(Alloc_param), Alloc_param, null);
            }
        }
示例#2
0
 /// <summary> Constructor based on a memory pointer. </summary>
 /// <param name="ptr_param">   The pointer parameter. </param>
 /// <param name="Alloc_param"> The allocate parameter. </param>
 public CStruct(IntPtr ptr_param, AllocatedMode Alloc_param)
 {
     Pointer           = ptr_param;
     Pointer_Allocated = Alloc_param;
     CopyPtrToStruct();
 }