locked
IUnknown and ComPtr

    Question

  • (I'm very new to COM, so this may make no sense, but...)

    I've implemented a custom font loader, and the interfaces are IUnknown.  I'm wondering if I can use a ComPtr to manage the reference counts for IUknown, or do I need to manually manage AddRef & Release for these objects?  E.g., can I define something like: ComPtr<IDWriteFontFile> currentFile, and let the ComPtr automatically handle AddRef & Release, rather than managing those calls manually?

    Thanks.

    Saturday, September 01, 2012 4:24 AM

Answers

  • I think you can. I myself use ComPtr<IInspectable> for WinRT objects, to correctly handle reference counts, and it works well.
    • Marked as answer by Mike Muir Sunday, September 02, 2012 1:08 AM
    Saturday, September 01, 2012 9:15 PM

All replies

  • I think you can. I myself use ComPtr<IInspectable> for WinRT objects, to correctly handle reference counts, and it works well.
    • Marked as answer by Mike Muir Sunday, September 02, 2012 1:08 AM
    Saturday, September 01, 2012 9:15 PM
  • Thanks!  I'll probably throw together a test at some point to confirm, but it sounds like it should work.
    Sunday, September 02, 2012 1:09 AM