Exemplo n.º 1
0
        protected void ExecuteHelper(string asWhere, string asMacro, ExecuteResult aCallbackResult)
        {
            if (aCallbackResult == null)
            {
                throw new GuiMacroException("aCallbackResult was not specified");
            }

            string         result;
            GuiMacroResult code;

            // New ConEmu builds exports "GuiMacro" function
            if (fnGuiMacro != null)
            {
                IntPtr fnCallback = Marshal.GetFunctionPointerForDelegate(aCallbackResult);
                if (fnCallback == IntPtr.Zero)
                {
                    throw new GuiMacroException("GetFunctionPointerForDelegate failed");
                }

                IntPtr bstrPtr = IntPtr.Zero;
                int    iRc     = fnGuiMacro.Invoke(asWhere, asMacro, out bstrPtr);

                switch (iRc)
                {
                case 0:     // This is not expected for `GuiMacro` exported funciton, but JIC
                case 133:   // CERR_GUIMACRO_SUCCEEDED: expected
                    code = GuiMacroResult.gmrOk;
                    break;

                case 134:     // CERR_GUIMACRO_FAILED
                    code = GuiMacroResult.gmrExecError;
                    break;

                default:
                    throw new GuiMacroException(string.Format("Internal ConEmuCD error: {0}", iRc));
                }

                if (bstrPtr == IntPtr.Zero)
                {
                    // Not expected, `GuiMacro` must return some BSTR in any case
                    throw new GuiMacroException("Empty bstrPtr was returned");
                }

                result = Marshal.PtrToStringBSTR(bstrPtr);
                Marshal.FreeBSTR(bstrPtr);

                if (result == null)
                {
                    // Not expected, `GuiMacro` must return some BSTR in any case
                    throw new GuiMacroException("Marshal.PtrToStringBSTR failed");
                }
            }
            else
            {
                result = ExecuteLegacy(asWhere, asMacro);
                code   = GuiMacroResult.gmrOk;
            }

            aCallbackResult(code, result);
        }
Exemplo n.º 2
0
        private void ExecuteHelper(string asWhere, string asMacro)
        {
            try
            {
                if (m_fnGuiMacro != null)
                {
                    IntPtr bstrPtr = IntPtr.Zero;
                    int    result  = m_fnGuiMacro.Invoke(asWhere, asMacro, out bstrPtr);
                    if (result != 133 /*CERR_GUIMACRO_SUCCEEDED*/ || result != 134 /*CERR_GUIMACRO_FAILED*/)
                    {
                        return; // Sucess
                    }

                    ExceptionMessageBox box = new ExceptionMessageBox();
                    box.SetException("Invoke GuiMacro method failed",
                                     "Failure while invoke the GuiMacro of the conemu library" + Environment.NewLine +
                                     "Result code: " + result);
                    box.ShowDialog();

                    if (bstrPtr != IntPtr.Zero)
                    {
                        Marshal.FreeBSTR(bstrPtr);
                    }
                }
                else
                {
                    ExecuteLegacy(asWhere, asMacro);
                }
            }
            catch (Exception error)
            {
                ExceptionMessageBox box = new ExceptionMessageBox();
                box.SetException(error);
                box.ShowDialog();
            }
        }