Create the ObjectARX MFC Application Skeleton

To create a project for an ObjectARX MFC application

  1. Create a new MFC DLL project called AsdkAcUiSample.
  2. In the Application Settings, select MFC extension DLL, and click Finish.
  3. Open the generated CPP file. Remove the AFX_EXTENSION_MODULE call, add the AC_IMPLEMENT_EXTENSION_MODULE call, and revise the DllMain() function as described in the CAcModuleResourceOverride Class section.
  4. Add the following code to set up the AutoCAD command and acrxEntryPoint:
void dialogCreate()
{
    acutPrintf("\nAcUi Dialog Sample");
}

The following addCommand() call uses the module resource instance from the AC_IMPLEMENT_EXTENSION_MODULE macro:

static void initApp()
{
    CAcModuleResourceOverride resOverride;
    acedRegCmds->addCommand(
        "ASDK_ACUI_SAMPLE", 
        "ASDKACUISAMPLE", 
        "ACUISAMPLE", 
        ACRX_CMD_MODAL, 
        dialogCreate,
        NULL,
        -1,
        theArxDLL.ModuleResourceInstance());
}

The following unloadApp() function is called when the application unloads. At this time it is important to detach the resource instance:

static void unloadApp()
{
    // Do other cleanup tasks here  
    acedRegCmds->removeGroup("ASDK_ACUI_SAMPLE");
    theArxDLL.DetachInstance();
}
// Entry point
//
extern "C" AcRx::AppRetCode acrxEntryPoint(
    AcRx::AppMsgCode msg, void* appId)
{
    switch( msg ) 
    {
        case AcRx::kInitAppMsg: 
            acrxDynamicLinker->unlockApplication(appId);
            acrxDynamicLinker->registerAppMDIAware(appId);
            initApp(); 
            break;
        case AcRx::kUnloadAppMsg: 
            unloadApp(); 
            break;
        case AcRx::kInitDialogMsg:
            break;
        default:
            break;
    }
    return AcRx::kRetOK;
}

Create an AsdkAcUiSample.h header file and add the following lines to the file:

#include "resource.h" // main symbols
#define PI  3.14159265359
// Forward declaration for the entry point function of 
// our application
void testCreate();

Add the following include files to AsdkAcUiSample.cpp:

#include "AsdkAcUiSample.h"
#include "AcExtensionModule.h"

You also need to add the ObjectARX libraries to the project file, change the .dll extension to .arx, and modify the .def file with the proper exports.

Then you can compile and load the application.