none
COM & IDisposable interface RRS feed

  • Question

  • I have a COM server written in .Net. which uses an explicit interface.

    The problem is that the IDisposable interface isn't exported to the tlb file.

    The code look like

    [ComVisible(true)]
    interface IFoo {
      ...
    }

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(IFoo))]
    public class Foo : IFoo, IDisposable {
      ...
    }

    The type library generated with tlbexp
    [
      odl,
      uuid(00E39AE2-B2A2-4BD3-81C1-CA6A88DFFCA8),
      version(1.0),
      dual,
      oleautomation,
      custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, IFoo)

    ]
    interface IFoo: IDispatch {
      ...
    };

    [
      uuid(F02DC690-40A3-4C62-B5CA-6A700EAFE651),
      version(1.0),
      custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Foo)
    ]
    coclass Foo {
        interface _Object;
        interface IDisposable;
        [default] interface IFoo;
    };

    The IDisposable interface isn't listed in the tlb file. I can't call Dispose on a Foo object.



    Monday, June 2, 2008 2:24 PM

Answers

  • It's right there, the second interface in the coclass declaration.  You just need to cast the object instance to an IDisposable reference, the equivalent of calling QueryInterface() in C/C++ code.  This is standard COM usage for a COM object that supports multiple interfaces.
    Hans Passant.
    • Marked as answer by Bruno Yu Friday, June 6, 2008 6:10 AM
    Monday, June 2, 2008 8:52 PM
    Moderator