COM wrappers can be created as separate DLLs, or combined with your ObjectARX application. A separate DLL allows the system to manage resources more efficiently; it can release COM objects when they are not needed even if the ObjectARX application cannot be unloaded. A combined DLL may be convenient if you intend to support only in-process clients. In either case, you can use the Microsoft Visual C++ ATL project setup interface to simplify the process. The following sections provide procedures that apply to both types of wrappers:
To set up a project for a COM wrapper
-
Make sure
axdb.dll, which should be in the same directory as
acad.exe, is in the search path.
- In Microsoft Visual C++, start a new ATL project.
- When prompted, enter a project name.
- Configure your project to build a DLL server. Additional project settings are optional.
- Finish your project setup and save the new project.
This procedure sets up the basic COM framework for your wrapper application, including an IDL file and a DLL housing for the object.
In the next procedure, you add a new interface. Microsoft Visual C++ creates a skeletal interface definition and its corresponding COM class. Later, you can add methods and properties to this interface.
To add a COM object and interface to your project
-
Using the Microsoft wizard interface, add a new simple ATL object.
- Enter a C++ short name when prompted to do so.
The wizard supplies default values for the remaining names. You can modify the suggested names if you wish.
- On the appropriate wizard page, select support for
ISupportErrorInfo.
- Close the wizard.
The following procedure configures your project to work with AutoCAD Automation.
To configure your ATL project for use with AutoCAD Automation interfaces
-
In the project's C++ properties, enable C++ exceptions.
- In the project's linker settings, add
axdb.lib,
oleaprot.lib, and any other referenced ObjectARX libraries to the linker dependency list.
- Save the property settings and close the dialog box.
Follow the next procedure only if you are combining ObjectARX code with the COM wrapper.
To incorporate an existing ObjectARX application into your ATL project
-
Add the CPP and H files from your ObjectARX application to your project.
- Add project settings, as well as include and library paths, as appropriate for an ObjectARX application.
-
In the project definitions (DEF) file, add the following lines to the EXPORTS section:
acrxEntryPoint PRIVATE
acrxGetApiVersion PRIVATE
In the
acrxEntryPoint() function, add a call to
DllRegisterServer in the
kInitAppMsg case block, as shown below. (This step is not necessary if you are certain your server is registered.)
case AcRx::kInitAppMsg:
//unlock the application
acrxDynamicLinker->unlockApplication(pkt);
acrxRegisterAppMDIAware(pkt);
//register ourselves
DllRegisterServer();
break;
If other initialization or cleanup occurs in the
acrxEntryPoint() function, move this initialization to your
DllMain.
Note:
In AutoCAD 2000 or later, AutoCAD tries to call
DllMain on any ObjectARX application that is loaded by standard AutoCAD mechanisms. Therefore, it is safe to place initialization code in
DllMain. However, a registered DLL that combines an ObjectARX application with a COM server can be loaded either by AutoCAD itself, or by the Windows COM subsystem. If COM loads the application, only
DllMain
will be called. For this reason, it is often preferable to perform ObjectARX initialization in
DllMain.
Choose “Rebuild All” from the Build menu to build your combined COM wrapper DLL file.