Связь между объектами COM
От: Hawk Россия  
Дата: 08.11.02 06:19
Оценка:
Есть два объекта, которые должны ссылаться друг на друга. Их интерфейсы описываются так (с помощью атрибутов в VS.NET):

Foo.h

// IFoo

[
    object,
    uuid("3301B939-CA8B-4267-BDA5-9A9889EA98E6"),
    dual,    helpstring("IFoo Interface"),
    pointer_default(unique)
]
__interface IFoo : IDispatch
{
    [id(1), helpstring("method SetBar")] HRESULT SetBar([in] IBar* pBar);
    [id(2), helpstring("method GetBar")] HRESULT GetBar([out,retval] IBar** pBar);
};
...


Bar.h

// IBar

[
    object,
    uuid("947522B2-FA94-4173-A834-3CF41FB2C47E"),
    dual,    helpstring("IBar Interface"),
    pointer_default(unique)
]
__interface IBar : IDispatch
{
    [id(1), helpstring("method SetFoo")] HRESULT SetFoo([in] IFoo* pFoo);
    [id(2), helpstring("method GetFoo")] HRESULT GetFoo([out,retval] IFoo** pFoo);
};
...


Данные кострукции затем преобразуются (автоматически) в IDL-файл:

_Module.idl

[
    object,
    uuid("947522B2-FA94-4173-A834-3CF41FB2C47E"),
    dual,
    helpstring("IBar Interface"),
    pointer_default(unique)
] 
...
interface IBar : IDispatch {
...
    [id(1), helpstring("method SetFoo")] HRESULT SetFoo([in] IFoo* pFoo);
    [id(2), helpstring("method GetFoo")] HRESULT GetFoo([out,retval] IFoo** pFoo);
};

[
    object,
    uuid("3301B939-CA8B-4267-BDA5-9A9889EA98E6"),
    dual,    helpstring("IFoo Interface"),
    pointer_default(unique)
]
__interface IFoo : IDispatch
{
    [id(1), helpstring("method SetBar")] HRESULT SetBar([in] IBar* pBar);
    [id(2), helpstring("method GetBar")] HRESULT GetBar([out,retval] IBar** pBar);
};


При компиляции компилятор, естественно, ругается, т.к. не может найти IFoo при компиляции IBar. Первый вопрос: Как быть? Второй вопрос: Есть ли другие (быть может более эффективные и/или универсальные) способы связи объектов в COM?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.