Wrapping COM and C++

Top  Previous  Next

If you write a console EXE in C++ you should follow this high level structure:

 

int _tmain(int argc, _TCHAR* argv[])

{

       HRESULT Result = CoInitialize (NULL); // Start COM...

 

       if (SUCCEEDED(Result))

               Result = YourInventorProgram();

 

       CoUninitialize(); // ...end COM

 

       return 0;

}

 

In this way the smart pointers and COM objects will be constructed and destroyed properly, as long as you keep them on the stack (i.e. local to some function).

 

If you had a global variable like the error manager outside of YourInventorProgram you would need to be able to handle it explictly, and you'd probably get errors when you program closes down (because the global pointer will be handled after CoUnitialize has been called, and COM is no longer active).

 

 

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