/// <summary> /// Sets the console for Interactive display. Uses GSDisplay Class to handle display events /// UTF8 is setup for encoding. Callback handlers for StdIO are also set by calling base functions /// </summary> /// <returns>True if successful</returns> protected bool SetConsole() { _pInstance = IntPtr.Zero; IntPtr displayDevice_callback_handle; _gsDisplay = new GSDisplay(); string[] strArray = GetArgsForDisplay(); // allocate a memory for the display device callback handler displayDevice_callback_handle = Marshal.AllocCoTaskMem(_gsDisplay._callback.size); // copy display device callback structure content to the pre-allocated block of memory Marshal.StructureToPtr(_gsDisplay._callback, displayDevice_callback_handle, true); _errNo = gsNewInstance(out _pInstance, IntPtr.Zero); if (_errNo != 0) { return(false); } else { try { _errNo = gsSetArgEncoding(_pInstance, GS_ARG_ENCODING.UTF8); if (_errNo < 0) { return(false); } _errNo = gsSetDisplayCallback(_pInstance, displayDevice_callback_handle); if (_errNo < 0) { return(false); } _errNo = gsInitArgs(_pInstance, strArray.Length, strArray); if (_errNo != 0) { return(false); } _errNo = gsSetStdio(_pInstance, StdIOIn, StdIOOut, StdIOErr); if (_errNo != 0) { return(false); } } catch (Exception) { _pInstance = IntPtr.Zero; return(false); } } return(true); }
/// <summary> /// Delete the stored Instance handler and make Display class null /// </summary> private void CleanUp() { if (_pInstance != IntPtr.Zero) { gsExit(_pInstance); gsDeleteInstance(_pInstance); } if (_gsDisplay != null) { _gsDisplay = null; } }