When I use an ActiveX client application on a computer that has AutoCAD based products installed, I don't know which 'AutoCAD' I am accessing. Is there a way of determining this?
The following code obtains the running (or creates a new instance if none exists) of AutoCAD. Its version is determined by the registry key.
CComQIPtr<IAcadApplication, &IID_IAcadApplication> gpApp;
HRESULT hr = S_OK;
//get the current version's CLSID
hr = CLSIDFromProgID(L"AutoCAD.Application", &clsid);
hr = GetActiveObject(clsid, NULL, &pIUnk);
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER,
gpApp = pIUnk;
if(FAILED(hr) || !gpApp)
Therefore, if CoCreateInstance() on the CLSID we got from CLSIDFromProgID() of "AutoCAD.Application" succeeded, we know AutoCAD is running.
The problem is that all the other family products that have an
AutoCAD engine use the same ProID, "AutoCAD.Application" thus one can't tell which family member receives the client's request.
However, each family product has its own Automation Extension with specific interface progID, and it's this information that determines which AutoCAD based program is running.
For example, once you have the IAcadApplication object, you can call its GetInterfaceObject() method.