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.
The easiest way to do this is to add the ObjectARX include and library directories to your MSVC++ environment settings (in the Microsoft Visual Studio menu under Tools Options Projects and Solutions VC++ Directories). You can also specify the locations in the Project Properties, but you'll need to include full paths to the files for every project you create.
If you prefer, you can control this warning instead by using #pragma warning statements. See the Microsoft documentation for more information about #pragma warning statements.
For example, the minimum code shown below requires rxapi.lib and acdb24.lib.
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.
#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.
Once you have added these two source files, you can build a basic ObjectARX application.
(arxload "program_name")
For more information, see Loading an ObjectARX Application.