public CHAR_INFO[] GetConsoleBuffer()
        {
            unsafe
            {
                ConsoleBufferInfo *bufferInfo = (ConsoleBufferInfo *)_consoleBufferInfo.Get();
                CHAR_INFO[]        buffer     = new CHAR_INFO[bufferInfo->BufferSize];

                fixed(CHAR_INFO *dst = buffer)
                {
                    WinApi.CopyMemory(new IntPtr(dst), new IntPtr(_consoleBuffer.Get()),
                                      (uint)(buffer.Length * Marshal.SizeOf(typeof(CHAR_INFO))));
                }

                return(buffer);

                //CONSOLE_SCREEN_BUFFER_INFO* consoleScreenInfo = (CONSOLE_SCREEN_BUFFER_INFO*)
                //    _consoleScreenInfo.Get();
                //CHAR_INFO[] buffer = new CHAR_INFO[_consoleBuffer.Size];

                //fixed (CHAR_INFO* dst = buffer)
                //{
                //    WinApi.CopyMemory(new IntPtr(dst), new IntPtr(_consoleBuffer.Get()),
                //        (uint)(buffer.Length * Marshal.SizeOf(typeof(CHAR_INFO))));
                //}

                //return buffer;
            }
        }
        private void CreateSharedObjects(int consoleProcessId)
        {
            // Create objects in shared memory.
            _consoleParams.Create(string.Format("Console_consoleParams_{0}", consoleProcessId), 1,
                                  SyncObjectTypes.SyncObjRequest);
            _consoleScreenInfo.Create(string.Format("Console_consoleInfo_{0}", consoleProcessId), 1,
                                      SyncObjectTypes.SyncObjRequest);
            _consoleCursorInfo.Create(string.Format("Console_cursorInfo_{0}", consoleProcessId), 1,
                                      SyncObjectTypes.SyncObjRequest);
            _consoleBufferInfo.Create(string.Format("Console_consoleBufferInfo_{0}", consoleProcessId), 1,
                                      SyncObjectTypes.SyncObjBoth);
            _consoleBuffer.Create(string.Format("Console_consoleBuffer_{0}", consoleProcessId), 0xFFFF,
                                  SyncObjectTypes.SyncObjNone);
            _consoleCopyInfo.Create(string.Format("Console_consoleCopyInfo_{0}", consoleProcessId), 1,
                                    SyncObjectTypes.SyncObjBoth);
            _consolePasteInfo.Create(string.Format("Console_consolePasteInfo_{0}", consoleProcessId), 1,
                                     SyncObjectTypes.SyncObjBoth);
            _consoleMouseEvent.Create(string.Format("Console_formatMouseEvent_{0}", consoleProcessId), 1,
                                      SyncObjectTypes.SyncObjBoth);
            _consoleNewSizeInfo.Create(string.Format("Console_newConsoleSize_{0}", consoleProcessId), 1,
                                       SyncObjectTypes.SyncObjRequest);
            _consoleNewScrollPos.Create(string.Format("Console_newScrollPos_{0}", consoleProcessId), 1,
                                        SyncObjectTypes.SyncObjRequest);

            // Initialize console buffer.
            unsafe
            {
                CHAR_INFO charInfo;

                charInfo.Attributes  = 0;
                charInfo.UnicodeChar = ' ';
                for (int i = 0; i < 0xFFFF; ++i)
                {
                    WinApi.CopyMemory(new IntPtr(_consoleBuffer.Get(i)), new IntPtr(&charInfo),
                                      (uint)sizeof(CHAR_INFO));
                }
            }
        }