# Gracefully shutting down your OEM application

**URL:** <https://forum.techsoft3d.com/t/gracefully-shutting-down-your-oem-application/725>\
**Category:** AutoCAD OEM\
**Created:** [April 1, 2022, 1:00pm UTC](https://forum.techsoft3d.com/t/gracefully-shutting-down-your-oem-application/725 "2022-04-01T13:00:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paavo](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@paavo](https://forum.techsoft3d.com/u/paavo)\
**Post date:** [April 1, 2022, 1:00pm UTC](https://forum.techsoft3d.com/t/gracefully-shutting-down-your-oem-application/725/1 "2022-04-01T13:00:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paavo](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@paavo](https://forum.techsoft3d.com/u/paavo)\
**Post date:** [November 24, 2022, 5:21pm UTC](https://forum.techsoft3d.com/t/gracefully-shutting-down-your-oem-application/725/4 "2022-11-24T17:21:55Z")

</div>

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:

> **[How to Exit from AutoCAD or AutoCAD OEM](https://adndevblog.typepad.com/autocad/2022/11/how-to-exit-from-autocad-or-autocad-oem.html)**
>
> By Madhukar Moogala There may be a situation where your Arx application needs to exit AutoCAD if the license check or some other business logic fails When aborting, use AcDbHostApplicationServices::fatalError() Or, acrx\_abort() instead of a direct or...

---

<div class="post-metadata">

**Author:** ![jm1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/jm1/32/317_2.png) [@jm1](https://forum.techsoft3d.com/u/jm1)\
**Post date:** [May 29, 2023, 2:56pm UTC](https://forum.techsoft3d.com/t/gracefully-shutting-down-your-oem-application/725/5 "2023-05-29T14:56:23Z")

</div>

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

```auto
		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);`

---

<div class="post-metadata">

**Author:** ![paavo](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@paavo](https://forum.techsoft3d.com/u/paavo)\
**Post date:** [June 18, 2023, 12:16pm UTC](https://forum.techsoft3d.com/t/gracefully-shutting-down-your-oem-application/725/6 "2023-06-18T12:16:58Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/b/b83baa4ec39b54170e76401db1b77fb1ef2bdc38.png)

The whole process is explained in this training video (including downloadable licensing sample ARX), go to [Autodesk AutoCAD OEM - Tech Soft 3D Developer Zone](https://developer.techsoft3d.com/platform-products/autocad_oem/training) :

 ![image](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/7/79cf369775e3763d7c2dd1afdbab188b08706da5.jpeg)
