Getting or running an Inventor Instance

Top  Previous  Next

This code runs Inventor if it is not already running:


    CLSID InvAppClsid; 

    HRESULT Result = CLSIDFromProgID (L"Inventor.Application", &InvAppClsid);

    if (FAILED(Result)) 

        return Result;


    // See if Inventor is already running...

    CComPtr<IUnknown> pInvAppUnk;

    Result = ::GetActiveObject (InvAppClsid, NULL, &pInvAppUnk);

    if (FAILED (Result)) {

        // Inventor is not already running, so try to start it...

        TRACE (L"Could not get hold of an active Inventor , will start a new session\n");

        Result = CoCreateInstance (InvAppClsid, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IUnknown), (void **) &pInvAppUnk);

        if (FAILED (Result)){

            TRACE (L"*** Failed to create a new Inventor application ***\n");

            return Result;





    CComPtr<Application> pInvApp;

    Result = pInvAppUnk->QueryInterface (__uuidof(Application), (void **) &pInvApp);

    if (FAILED(Result)) return Result;


After that you can carry on an interact with Inventor with pInvApp.


How to correct it if CLSIDFromProgID fails.



Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)