Note that there are some explanatory texts on larger screens.

plurals
  1. PO#import directive reference counting problems
    primarykey
    data
    text
    <p>I've been looking into the different ways to call COM components from my MFC C++ application (VS 2008) and while using Microsoft Office automation as an example, I came across <a href="http://support.microsoft.com/kb/196776" rel="nofollow">MS KB article #196776</a> (last modified March 13, 2008) which states the following: </p> <blockquote> <p>There are three basic ways you can use Automation: MFC, #import, and C/C++:</p> <ul> <li>With MFC, use the Visual C++ ClassWizard to generate "wrapper classes" from the Microsoft Office type libraries. These classes, as well as other MFC classes, such as COleVariant, COleSafeArray, COleException, simplify the tasks of Automation. This method is <strong>usually recommended</strong> over the others, and most of the Microsoft Knowledge Base examples use MFC.</li> <li>#import, a new directive that became available with Visual C++ 5.0, creates VC++ "smart pointers" from a specified type library. It is very powerful, but often <strong>not recommended because of reference-counting problems</strong> that typically occur when used with the Microsoft Office applications.</li> <li>C/C++ Automation is much more difficult, but sometimes necessary to avoid overhead with MFC, or problems with #import. Basically, you work with such APIs as CoCreateInstance(), and COM interfaces such as IDispatch and IUnknown.</li> </ul> </blockquote> <p>I've always preferred using #import over generating additional "wrapper classes" since it's easier to add new methods when the COM server has been updated (and I don't need to rerun the ClassWizard), however now I'm concerned I've been taking the wrong approach, is this problem with reference counting specific to Microsoft Office or to all COM automation components? If it's only specific to Office how do I avoid introducing similar problems into the COM servers I create?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload