Setting up an ObjectARX Project Using Microsoft Visual Studio

The first step in building an ObjectARX application is to set up a project in Microsoft Visual Studio. This section lists the project settings and minimum files required to build a basic ObjectARX application.

Alternatively, you can create a new ObjectARX project using the ObjectARX Wizards for AutoCAD, which you can install from the ObjectARX utils\ObjARXWiz directory.
Note: The ObjectARX Wizards have been removed from the ObjectARX SDK. You can find the latest version at the AutoCAD Developer Center.

Use the following settings for your project

You will need to add source file(s) to the new project. If you already have source files or are using sample program source files, add these files.

This example shows the minimum code needed to make an ObjectARX program.

Add a new C++ source file to the project and enter the following code:

#include "rxregsvc.h"
#include "acutads.h"
// Simple acrxEntryPoint code. Normally intialization and cleanup
// (such as registering and removing commands) should be done here.
//
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
    switch(msg) {
    case AcRx::kInitAppMsg:
        // Allow application to be unloaded
        // Without this statement, AutoCAD will
        // not allow the application to be unloaded
        // except on AutoCAD exit.
        //
        acrxUnlockApplication(appId);
        // Register application as MDI aware. 
        // Without this statement, AutoCAD will
        // switch to SDI mode when loading the
        // application.
        //
        acrxRegisterAppMDIAware(appId);
        acutPrintf("\nExample Application Loaded");
    break;
    case AcRx::kUnloadAppMsg:
        acutPrintf("\nExample Application Unloaded");
    break;
    }
    return AcRx::kRetOK;
}

The project also needs a definition file. Add a new text file to the project and name it with a .def extension.

Enter the following code in the DEF file

LIBRARY "objectarx_program_name.arx"
EXPORTS
    acrxEntryPoint PRIVATE
    acrxGetApiVersion PRIVATE

The EXPORTS section should be present and must contain at least the acrxEntryPoint function (unless you have used another mechanism to export this function, like the Windows _declspec(dllexport) convention).

Using PRIVATE in the DEF file prevents these symbols from appearing in an import library for this ObjectARX application. The symbol will still appear in the application's export table, allowing AutoCAD to find and call the symbol. This is important because every ObjectARX application or Object Enabler must have its own implementation of these functions. The application gets the implementation of acrxGetApiVersion by virtue of linking to the static library rxapi.lib. If ObjectARX application app2 uses symbols from ObjectARX application app1 by linking to app1.lib, it would be an error for app2 to get its definition of acrxGetApiVersion from the app1 import library. Using PRIVATE in the DEF file will prevent this. Making certain to link to rxapi.lib prior to linking to any import library for another ObjectARX application will also prevent this.

The LIBRARY name should match the file name of the ObjectARX file you are going to create and must show an .arx extension. For example, if your desired output file name is test.arx, the LIBRARY statement in your DEF file should show the full name test.arx.

Note: If you wish, you can include the standard ObjectARX DEF file, AcRxDefault.def, in your project. This file defines the required ObjectARX exports properly and is found in the \inc SDK directory. It does not use a LIBRARY statement.

Once you have added these two source files, you can build a basic ObjectARX application.

To test the application, start AutoCAD and load the program using one of the following methods

For more information, see Loading an ObjectARX Application.