Connect to Inventor from COM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been using this function for many years...
bool ConnectToInventor ()
{
CLSID InvAppClsid;
HRESULT hRes = CLSIDFromProgID (L"Inventor.Application", &InvAppClsid);
if (FAILED(hRes)) {
pInvApp = nullptr ;
ShowCOMError (hRes,L"ConnectToInventor, CLSIDFromProgID failed, admin vs normal user conflict?") ;
return false;
}
// See if Inventor is already running...
CComPtr<IUnknown>pInvAppUnk = nullptr ;
hRes = ::GetActiveObject (InvAppClsid, NULL, &pInvAppUnk);
if (FAILED (hRes)) {
// Inventor is not already running, so try to start it...
const int ikAnswer = YesNoBoxW (L"Shall I run Inventor?") ;
if (ikAnswer == IDNO) {
return false ;
}
hRes = CoCreateInstance (InvAppClsid, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IUnknown), (void **) &pInvAppUnk);
if (FAILED (hRes)){
pInvApp = nullptr ;
ShowCOMError (hRes,L"ConnectToInventor,CoCreateInstance failed") ;
return false;
}
}
// Get the pointer to the Inventor application...
hRes = pInvAppUnk->QueryInterface (__uuidof(Application), (void **)&pInvApp);
if (FAILED(hRes)) {
ShowCOMError (hRes,L"ConnectToInventor,QueryInterface failed") ;
false;
}
return true ;
}
...but sometimes it fails and runs a second instance of Inventor.
Can anyone tell me why the random failure might be occurring?