Exit Rhino from C++ code/function unavailable?

I have a need to exit the Rhino process from a C++ plug-in, but when I call

RhinoApp().ExitRhino(); 

in my code, the linker complains with
image

My question is: can I exit Rhino from C++ code, and if so, how?

RunScript with "_Exit"?

No, I mean unconditional exit - user should not be able to press “Cancel”.

I’ve solved it by using a callback function pointer to .NET code, where I can call RhinoApp.Exit(). Plus it is easier in .NET to show the user some dialogs & ask them to save their work before the exit.

Hi @menno,

CRhinoApp::ExitRhino() is not a publicly exported function, thus the unresolved external symbol error.

You might try one of these:

C#:

public class QuitCommand : Command
{
  public override string EnglishName => "Quit";

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
    doc.Modified = false;
    PostMessage(RhinoApp.MainWindowHandle(), 0x0010 /*WM_CLOSE*/, 0, 0);
    return Result.Success;
  }

  [DllImport("User32.Dll")]
  private static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
}

C++:

CRhinoCommand::result CCommandQuit::RunCommand(const CRhinoCommandContext& context)
{
  context.m_doc.SetModifiedFlag(FALSE);
  ::PostMessage(RhinoApp().MainWnd(), WM_CLOSE, 0L, 0L);
  return CRhinoCommand::success;
}

– Dale

1 Like