/** ..and each time we want to read, data, we must explicitly fetch the struct. */
 internal void GetControlData()
 {
     controlStruct.bufferstates = -1;
     controlStruct = (ControlChannelStruct)Marshal.PtrToStructure(controlChannel.data, typeof(ControlChannelStruct));
 }
        public FrameTransport()
        {
            sharedInfoSize = (uint)Marshal.SizeOf((Type)typeof(ControlChannelStruct));

            haveFrame = false;

            bitmapData = null;
            bitmapDataSize = 0;

            frameChannel1 = null;
            frameChannel2 = null;

            controlStruct = new ControlChannelStruct();
            controlStruct.bufferstates = 1;
            controlStruct.buffer1.bufid = -1;
            controlStruct.buffer2.bufid = -1;
            controlStruct.buffer1.clientpointer = 1;
            controlStruct.buffer2.clientpointer = 2;
            controlStruct.fourcccount = 0;
            controlStruct.buftype = BufferType.WinBuffers;

            // Mapping the control channel
            controlChannel = new SharedMemoryChannel();
            bool success = controlChannel.CreateMapping(sharedInfoSize);
            if (!success) throw new Exception("Unable to create memory mapping for video frame transport");

            // Opening the control channel for read-write
            controlChannel.OpenMapping(controlChannel.key);
            int error = Win32.GetLastError();
            if (error != 0) throw new Exception("Unable to map memory for video frame transport");
        }