0

I have a Dll Project with IDL interfaces. I Want to have to interfaces in my dll that one of them can be derived from other. I created two interfaces with ATL Simple Object Wizard.

[
    object,
    uuid(7359AF6C-6E90-4372-991F-556602CB3977),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface IZInterface : IDispatch{
    [id(1)] HRESULT ZGetStr([out,retval] BSTR* str);
    [id(2)] HRESULT GetSize([in,out] LONG* nSize);
};
[
    object,
    uuid(8CA6DBF2-E402-464D-96AE-3D6642D91E14),
    pointer_default(unique)
]
interface IBClass : IUnknown{
    [] HRESULT Method11([out,retval] LONG* l);
};
library DllStandardLib
{
    importlib("stdole2.tlb");
    [
        uuid(491DF659-012F-4C20-90AA-0CBC5BDE5A68)      
    ]
    coclass ZInterface
    {
        [default] interface IZInterface;
    };
        [
        uuid(43CE897F-17F2-4D45-9098-26B7AEE6EC23)      
    ]
    coclass BClass
    {
        [default] interface IBClass;
    };
};

now, i right click on CZInterface in Class View then Impelement Interface IBClass .

but in continer that is a C# project:

DllStandardLib.ZInterface dd = new DllStandardLib.ZInterface();
dd.Method11();//---> Error: DllStandardLib.ZInterface' does not contain a definition for 'Method11' and no extension method 'Method11' accepting a first argument of type ...

what is the problem in my project? I want the second (derived) interface knows all methods and properties of base interface. please help me!

nabegheh95
  • 195
  • 3
  • 19
  • IBClass derives from IUnknown, not from IZInterface. So of course this can't work. The ATL wizard doesn't help you do this, you have to do it by hand. Maybe you shouldn't. – Hans Passant Feb 18 '15 at 09:36

1 Answers1

1

Best thing is not to use the Object Wizard if you want to achive this. First, define your interfaces:

[
    object,
    uuid(7359AF6C-6E90-4372-991F-556602CB3977),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface IZInterface : IDispatch
{
    [id(1)] HRESULT ZGetStr([out,retval] BSTR* str);
    [id(2)] HRESULT GetSize([in,out] LONG* nSize);
};

[
    object,
    uuid(8CA6DBF2-E402-464D-96AE-3D6642D91E14),
    pointer_default(unique)
]
interface IBClass : IZInterface    // IBClass inherits from IZInterface
{
    [id(3)] HRESULT Method11([out,retval] LONG* l);
};

Then define your class, that implements the specialized interface. Do this within your library:

library DllStandardLib
{
    importlib("stdole2.tlb");

    [
        uuid(43CE897F-17F2-4D45-9098-26B7AEE6EC23)      
    ]
    coclass BClass
    {
        [default] interface IBClass;
    };

    // NOTE: No need for ZInterface coclass.
};

Note that the IZInterface class is not really needed, except you want to provide an separate implementation (= another class).

In order for the QueryInterface-calls to work, you should also add the interface to your COM interface map:

class CBClass : 
    // ...
{
    // ...

BEGIN_COM_MAP(CBClass)
    COM_INTERFACE_ENTRY(IBClass)
    COM_INTERFACE_ENTRY(IZInterface)
END_COM_MAP()

    // ...

    // IBClass-Member
    STDMETHOD(Method11)(LONG* l);    // Implement this in your source file (STDMETHODIMP CBClass::Method11(LONG* l) { return E_NOTIMPL; }
}

To call your IBClass interface members from .NET, you have to create an instance of the right class:

DllStandardLib.BClass bc = new DllStandardLib.BClass();
bc.Method11();
Carsten
  • 11,287
  • 7
  • 39
  • 62