private void LoadConEmuDll([NotNull] string asLibrary) { if (asLibrary == null) { throw new ArgumentNullException(nameof(asLibrary)); } if (_hConEmuCD != null) { return; } _hConEmuCD = WinApi.LoadLibrary(asLibrary); if (_hConEmuCD == null) { int errorCode = Marshal.GetLastWin32Error(); throw new GuiMacroException($"Can't load library, ErrCode={errorCode}\n{asLibrary}"); } const string fnName = "GuiMacro"; void * exportPtr = WinApi.GetProcAddress(_hConEmuCD, fnName); if (exportPtr == null) { UnloadConEmuDll(); throw new GuiMacroException($"Function {fnName} not found in library\n{asLibrary}\nUpdate ConEmu modules"); } _fnGuiMacro = (FGuiMacro)Marshal.GetDelegateForFunctionPointer((IntPtr)exportPtr, typeof(FGuiMacro)); }
public GuiMacro(string asLibrary) { ConEmuCD = IntPtr.Zero; fnConsoleMain3 = null; fnGuiMacro = null; libraryPath = asLibrary; LoadConEmuDll(asLibrary); }
public ConEmuMacro(string asLibrary) { m_ConEmuHandle = IntPtr.Zero; m_fnConsoleMain3 = null; m_fnGuiMacro = null; m_LibraryPath = asLibrary; LoadConEmuDll(asLibrary); }
private void LoadConEmuDll(string asLibrary) { try { if (m_ConEmuHandle != IntPtr.Zero) { return; } m_ConEmuHandle = LoadLibrary(asLibrary); if (m_ConEmuHandle == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to load the conemu library", "Failure while load the conemu library" + Environment.NewLine + "Library path: " + asLibrary + Environment.NewLine + "Last error code: " + error); box.ShowDialog(); return; } const string fnNameOld = "ConsoleMain3"; IntPtr ptrConsoleMain = GetProcAddress(m_ConEmuHandle, fnNameOld); const string fnNameNew = "GuiMacro"; IntPtr ptrGuiMacro = GetProcAddress(m_ConEmuHandle, fnNameNew); if (ptrConsoleMain == IntPtr.Zero && ptrGuiMacro == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to load the conemu library", "Failure while getting the addresses of the methods in the conemu library" + Environment.NewLine + "Library path: " + asLibrary + Environment.NewLine + "Methods: ConsoleMain3, GuiMacro" + Environment.NewLine + "Last error code: " + error); box.ShowDialog(); UnloadConEmuDll(); return; } m_fnGuiMacro = (FGuiMacro)Marshal.GetDelegateForFunctionPointer(ptrGuiMacro, typeof(FGuiMacro)); m_fnConsoleMain3 = (FConsoleMain3)Marshal.GetDelegateForFunctionPointer(ptrConsoleMain, typeof(FConsoleMain3)); } catch (Exception error) { UnloadConEmuDll(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
private void LoadConEmuDll(string asLibrary) { if (ConEmuCD != IntPtr.Zero) { return; } ConEmuCD = LoadLibrary(asLibrary); if (ConEmuCD == IntPtr.Zero) { int errorCode = Marshal.GetLastWin32Error(); throw new GuiMacroException(string.Format("Can't load library, ErrCode={0}\n{1}", errorCode, asLibrary)); } // int __stdcall ConsoleMain3(int anWorkMode/*0-Server&ComSpec,1-AltServer,2-Reserved*/, LPCWSTR asCmdLine) const string fnNameOld = "ConsoleMain3"; IntPtr ptrConsoleMain = GetProcAddress(ConEmuCD, fnNameOld); const string fnNameNew = "GuiMacro"; IntPtr ptrGuiMacro = GetProcAddress(ConEmuCD, fnNameNew); if ((ptrConsoleMain == IntPtr.Zero) && (ptrGuiMacro == IntPtr.Zero)) { UnloadConEmuDll(); throw new GuiMacroException(string.Format("Function {0} not found in library\n{1}\nUpdate ConEmu modules", fnNameOld, asLibrary)); } if (ptrGuiMacro != IntPtr.Zero) { // To call: ExecGuiMacro.Invoke(asWhere, asCommand, callbackDelegate); fnGuiMacro = (FGuiMacro)Marshal.GetDelegateForFunctionPointer(ptrGuiMacro, typeof(FGuiMacro)); } if (ptrConsoleMain != IntPtr.Zero) { // To call: ConsoleMain3.Invoke(0, cmdline); fnConsoleMain3 = (FConsoleMain3)Marshal.GetDelegateForFunctionPointer(ptrConsoleMain, typeof(FConsoleMain3)); } }
private void LoadConEmuDll([NotNull] string asLibrary) { if(asLibrary == null) throw new ArgumentNullException(nameof(asLibrary)); if(_hConEmuCD != null) return; _hConEmuCD = WinApi.LoadLibrary(asLibrary); if(_hConEmuCD == null) { int errorCode = Marshal.GetLastWin32Error(); throw new GuiMacroException($"Can't load library, ErrCode={errorCode}\n{asLibrary}"); } const string fnName = "GuiMacro"; void* exportPtr = WinApi.GetProcAddress(_hConEmuCD, fnName); if(exportPtr == null) { UnloadConEmuDll(); throw new GuiMacroException($"Function {fnName} not found in library\n{asLibrary}\nUpdate ConEmu modules"); } _fnGuiMacro = (FGuiMacro)Marshal.GetDelegateForFunctionPointer((IntPtr)exportPtr, typeof(FGuiMacro)); }