Gracefully shutting down your OEM application

Sometimes you need to shut down the running OEM application from your own modules. Typically during a runtime license check that fails.
There’s no API for that, but it’s fairly simple:
Here’s how you shut down OEM gracefully from C++:

    acedAlert(_T("Shutting down CoolCAD!"));

    ::PostMessage(adsw_acadMainWnd(), WM_CLOSE, 0, 0);

The user will be prompted to save his/her work before shut down.

1 Like

Here’s an alternative (better) way posted by Madhu. It allows for your OEM host and ObjectARX runtime modules to recover and do memory clean up:

1 Like

Hello Paavo,

when doing the license check during startup of AutoCAD, the first method may be a better solution. Combine the MessageBox() with ::PostMessage() like this

		if (!CheckLicense())
		{
			MessageBox(
				adsw_acadMainWnd(),
				_T("There are not enough licenses available!\n\n\nThe application\nwill SHUT DOWN now!"),
				_T("License Error"), MB_OK + MB_ICONWARNING);
			::PostMessage(adsw_acadMainWnd(), WM_CLOSE, 0, 0);

			/* this will show an (rather ugly) ARX error message */
			/* when returning with AcRx::kRetError, AutoCAD will close immediatley */
			/* BUT will show the error feedback messagebox after closing */
			//acrx_abort(_T("Application is Quitting Now!"));
			//return AcRx::kRetError;
		}

The application will finish loading and then quit gracefully. No need to save any drawing data, since no drawing has been loaded or edited yet.

When using the solution from Madhukar Moogala and using MessageBox() and acrx_abort(), you would have to click two message boxes. Just using acrx_abort() displays a rather ugly messagebox know for the display of (for instance) memory corruption errors. Also, the application is shuting down immediatley, followed with the AutoCAD error feedback window to report any errors to Autodesk. The feedback window is displayed with AutoCAD. I have not tested this with OEM, but it is safe to assume that this will NOT be displayed.

So, my advice: when checking for a valid license at application startup, go with MessageBox() and ::PostMessage(adsw_acadMainWnd(), WM_CLOSE, 0, 0);

1 Like

Thank you for your input Jens, very valuable as always. Depending on the situation this post now offers several alternatives. Thanks.

The original post was meant to provide a solution for a scenario when you need to shut down the OEM application during runtime. As a comment to Jens’ input I’d like to point out that as most of you know - for AutoCAD OEM based applications there is support in the developer platform to achieve the license check and shut down at startup.
All you need is a license validating ARX module that is configured as ‘Required’ in the MakeWizard:

The whole process is explained in this training video (including downloadable licensing sample ARX), go to Autodesk AutoCAD OEM - Tech Soft 3D Developer Zone :