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.
Use the following settings for your project
- Set the application type to DLL.
- Specify the ObjectARX library and include file locations.
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.
- For all configurations (debug and release), set the runtime library for linking to Multithreaded DLL (in your project’s Property Pages under Configuration Properties folder
C/C++ folder
Code Generation
Runtime Library).
-
For all configurations (debug and release), set the Detect 64-bit Portability Issues option to No (in your project’s Property Pages under Configuration Properties
C/C++ folder
General
Detect 64-bit Portability Issues). This setting suppresses compiler warning 4311 for pointer assignments that are not 64-bit compatible. Some ObjectARX header files contain such assignments.
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.
- Set the output file name (in your project’s Property Pages under Configuration Properties
Linker
General
Output File) to a name with an .arx extension. If you include a DEF file with a LIBRARY statement in your project, this name should match the LIBRARY value.
Note: LIBRARY statements are optional in DEF files. - Add the ObjectARX libraries necessary for your program (in your project’s Property Pages under Configuration Properties
Linker
Input
Additional Dependencies).
For example, the minimum code shown below requires rxapi.lib and acdb25.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.
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.
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
- Use the AutoLISP
arxload function.
(arxload "program_name")
- Use the ARX command.
- Use the APPLOAD command, which opens a dialog allowing you to maintain a list of applications to load/unload.
For more information, see Loading an ObjectARX Application.