Implementing an Entry Point for AutoCAD

AutoCAD calls into the ObjectARX module through acrxEntryPoint(), which replaces the main() function of a C++ program. You are responsible for implementing the acrxEntryPoint() function, as described in this section.

The acrxEntryPoint() function serves as the entry point for AutoCAD (or other host programs) to communicate with an ObjectARX application. ObjectARX programs can in turn communicate with AutoCAD by returning status codes. All requests to invoke functions defined with acedDefun() are made by the acrxEntryPoint() function. If you define a new command with ObjectARX or with the acedRegFunc() function, AutoCAD immediately executes the function associated with the command (see Loading an ObjectARX Application).

The acrxEntryPoint() function has the following signature:

extern "C"
AcRx::AppRetCode 
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt);
msg

Represents the message sent from the ObjectARX kernel to the application.

pkt

Holds packet data values.

AppRetCode

Contains the status code returned to AutoCAD.

Within the definition of the acrxEntryPoint() function, you write a switch statement or similar code to decipher messages from AutoCAD, perform appropriate actions related to each message, and return an integer status value.

Danger: Using kRetError for the final return value from the acrxEntryPoint() function will cause your application to be unloaded, except for the messages kOleUnloadAppMsg and kUnloadAppMsg. In these cases, if kRetError is returned, the application will not be unloaded.

The following code shows the skeleton of a valid switch statement:

extern "C"
AcRx::AppRetCode 
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) 
{
    switch(msg) {
        case AcRx::kInitAppMsg:
            break;
        case AcRx::kUnloadAppMsg:
            break;
        ...
        default:
            break;
    }
    return AcRx::kRetOK;
}