示例#1
0
        public IntPtr ToDLL_WavePointer()
        {
            DLL_Wave result = new DLL_Wave();

            result.Name    = StringToCCharArray(this.Name, DLL_Wave.NAME_STRING_LENGTH);
            result.xUnit   = StringToCCharArray(this.xUnit, DLL_Wave.UNIT_STRING_LENGTH);
            result.yUnit   = StringToCCharArray(this.yUnit, DLL_Wave.UNIT_STRING_LENGTH);
            result.X0      = this.X0;
            result.dX      = this.dX;
            result.Flags   = this.Flags;
            result.Time    = this.Time;
            result.Samples = this.Samples;
            result.y       = new float[this.Samples];
            for (int i = 0; i < this.Samples; i++)
            {
                result.y[i] = this.y[i];
            }

            //Allocate managed structure
            int    bytesToAllocate = (int)result.Samples * 4 + 56;
            IntPtr ptr             = Marshal.AllocHGlobal(bytesToAllocate); // Marshal.SizeOf(result));

            //Marshal the structure
            Marshal.StructureToPtr(result, ptr, false);

            var newPtr = new IntPtr(ptr.ToInt32() + 56); // move to first

            Marshal.Copy(result.y, 0, newPtr, result.y.Length);

            return(ptr);
        }
示例#2
0
        public static FAMOSDataObject FromDLL_WavePointer(IntPtr ptr)
        {
            DLL_Wave        dllWave = (DLL_Wave)Marshal.PtrToStructure(ptr, typeof(DLL_Wave));
            FAMOSDataObject result  = new FAMOSDataObject();

            result.xUnit   = TrimNullTerminatedString(dllWave.xUnit);
            result.yUnit   = TrimNullTerminatedString(dllWave.yUnit);
            result.Name    = TrimNullTerminatedString(dllWave.Name);
            result.dX      = dllWave.dX;
            result.X0      = dllWave.X0;
            result.Flags   = dllWave.Flags;
            result.Samples = dllWave.Samples;
            result.Time    = dllWave.Time;

            var newPtr = new IntPtr(ptr.ToInt32() + 56); // move to first

            result.y = new Single[dllWave.Samples];
            Marshal.Copy(newPtr, result.y, 0, result.y.Length);

            return(result);
        }