15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


COM Interfaces for inherited interfaces necessary?

Michael S. Scherotter -- mss@tartus.com
Thursday, April 11, 1996

Using VC4.1, NT3.51
I am creating an MFC COM object using CCmdTarget:
I want to use the Interface IPropertyPage2 with the following code in the header:

    DECLARE_INTERFACE_MAP()

    BEGIN_INTERFACE_PART(PropertyPage2, IPropertyPage2)
        INIT_INTERFACE_PART(TDPropertyPage, PropertyPage2)
        // IPropertyPage methods
        STDMETHOD(SetPageSite)(THIS_ LPPROPERTYPAGESITE pPageSite);
	    STDMETHOD(Activate)(THIS_ HWND hwndParent, LPCRECT lprc, BOOL bModal);
	    STDMETHOD(Deactivate)(THIS);
	    STDMETHOD(GetPageInfo)(THIS_ LPPROPPAGEINFO pPageInfo);
	    STDMETHOD(SetObjects)(THIS_ ULONG cObjects, LPUNKNOWN FAR* ppunk);
	    STDMETHOD(Show)(THIS_ UINT nCmdShow);
	    STDMETHOD(Move)(THIS_ LPCRECT prect);
	    STDMETHOD(IsPageDirty)(THIS);
	    STDMETHOD(Apply)(THIS);
	    STDMETHOD(Help)(THIS_ LPCOLESTR lpszHelpDir);
	    STDMETHOD(TranslateAccelerator)(THIS_ LPMSG lpMsg);
        // IPropertyPage2 methods
	    STDMETHOD(EditProperty)(THIS_ DISPID dispid);
    END_INTERFACE_PART(PropertyPage2)

My question is:
Do I need to do a inteface section for IPropertyPage as well?
What will happen when QueryInterfece(IPropertyPage) is called?

Thanks in advance,
Michael

-- 
Michael S. Scherotter            |Architectural Design Tools
Lead Software Developer          |AutoCAD Applications
Tartus Development, Inc.         |Custom CAD Solutions
630 Las Gallinas Ave #300        |__________________________ 
San Rafael, CA 94903                          mss@tartus.com
(415) 491-8925                          michael@charette.com
(415) 491-8921 (fax)               71035.1675@compuserve.com
____________________________________________________________



Gareth Jones -- gaj@i2.co.uk
Monday, April 15, 1996

[Mini-digest: 3 responses]

Michael Scherotter wrote:

Using VC4.1, NT3.51
I am creating an MFC COM object using CCmdTarget:
I want to use the Interface IPropertyPage2 with the following code in the header:

    DECLARE_INTERFACE_MAP()

<< code deleted>>

My question is:
Do I need to do a inteface section for IPropertyPage as well?
What will happen when QueryInterfece(IPropertyPage) is called?



You don't need an interface section in the header.

Assuming your IPropertyPage2 is a fully functional IPropertyPage,
(as you would normally expect a derived interface to be)
then you just need two entries in your INTERFACE_MAP in the .cpp file.

They should both point to the same embedded class, (PropertyPage2) but should have the IIDs of the two
interfaces respectively.

Gareth
-----------------------------------------------------------------
Gareth Jones         Software Consultant        visualize2analyse
gaj@i2.co.uk         i2 Ltd, Cambridge, UK      information2image

-----From: "John Elsbree" 

You don't need anything extra in the header. Just put two entries in the 
interface map in your .cpp file: one for each interface:

    BEGIN_INTERFACE_MAP(TDPropertyPage, CCmdTarget)
        INTERFACE_PART(TDPropertyPage, IID_IPropertyPage, PropertyPage2)
        INTERFACE_PART(TDPropertyPage, IID_IPropertyPage2, PropertyPage2)
    END_INTERFACE_MAP()

John (not speaking for Microsoft)

-----From: "David W. Gillett" 

> Do I need to do a inteface section for IPropertyPage as well?
> What will happen when QueryInterfece(IPropertyPage) is called?

  Although COM interfaces are easily coded in C++, they're not 
inherently C++-aware, and in particular there is no automatic 
inheritance.  Although you can probably re-use much of your 
*implementation* code, nothing in COM knows -- as I read it -- that 
there is any kind of special relationship between the IPropertyPage 
and IPropertyPage2 interfaces. 
  QueryInterface(IPropertyPage) should fail if you don't provide 
IPropertyPage.

Dave






| Вернуться в корень Архива |