3) Connecting to Inventor from a Windows MFC app.

Top  Previous  Next

Here is what your init of you MFC Windows application could look like:

 

BOOL CCollMakeApp::InitInstance()

{

       INITCOMMONCONTROLSEX InitCtrls;

       InitCtrls.dwSize = sizeof(InitCtrls);

       // Effettuare questa impostazione in modo da includere tutte le classi di controlli comuni da utilizzare

       // nell'applicazione.

       InitCtrls.dwICC = ICC_WIN95_CLASSES;

       InitCommonControlsEx(&InitCtrls);

 

   ::CoInitialize (NULL) ;

 

   if (!ExcelIsPresent()) {

       // Required if you use tabular iParts

       gLogger.Printf (ekErrMsg,L"Is Excel installed for Inventor?") ;

   }

 

   const bool kbInventorOK = ConnectToInventor();

 

   if (!kbInventorOK) {

       return FALSE ;

   }

 

       CWinApp::InitInstance();

 

       // Creare il gestore della shell se la finestra di dialogo contiene

       // controlli della visualizzazione elenco o struttura ad albero della shell.

       CShellManager* pShellManager = new CShellManager;

 

   // Initialization finished, run the main dialog of the application...

   {

           CMainDlg dlg;

           m_pMainWnd = &dlg;

           (void)dlg.DoModal();

   }

 

   // Program finished, tidy up...

 

   // Let the user see dialogs etc...

   GetInvAppPtr()->SilentOperation = VARIANT_FALSE ;

 

   // Free up Inventor interface globals

   DestroyInventorGlobals () ;

 

   ::CoUninitialize();

 

       // Eliminare il gestore della shell creato in precedenza.

       if (pShellManager != NULL)

       {

               delete pShellManager;

       }

 

       return FALSE;

}

 

CoInitialize and CoUninitialize are required to be able to use COM and its pointers. What I do is, in sequence:

 

1.CoInitialize starts up COM and COM pointer handling.
2.CreateInventorGlobals, sets up things useful to me as my Inventor program is running. It also starts Inventor running.
3.dlg.DoModal would be a dialog with buttons which the user can use to make objects with the Inventor API.
4.DestroyInventorGlobals tidies up my pointers after the dialog has finished (i.e. when I come out of DoModal).
5.::CoUninitialize for the final tidy up of the COM pointers and interface

 

Step 3 above is the heart of the program, a dialog box which talks to Inventor. You have to write that!

 

4) Inventor pointers and DestroyInventorGlobals

 

 

 

 

 

 

 

 

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