1

我想公开 CMainClass 对象的 ATL COM 集合,以便 C#、VB 或 C++ 客户端可以访问它。

我设置集合本身没有问题,但我不知道如何允许 COM 客户端访问 A、B 和 C 类。我是否应该使用包含的对象制作 A、B 和 C COM 对象一个 std::list<> 每个 ATL 集合本身对吗?

有没有更简单的方法来做到这一点?!?!

谢谢,保罗

class C
{
public:
    // get/set functions...

protected:
    std::string str1_;
    std::list< std::string > list1_;
};

class A
{
public:
    // get/set functions...

protected:
    std::list< C > list1_;
};

class B
{
public:
    // get/set functions...

protected:
    std::string str1_;
    std::string str2_;
};

class CMainClass
{
public:
    void GetA( A* a ) const;
    void SetA( const A& a );
    void GetB( B* b ) const;
    void SetB( const B& b );

protected:
    A a_;
    B b_;
};
4

1 回答 1

2

Google 在 ATL 中实现 IEnumVARIANT。

这里有一些有希望的链接。

http://msdn.microsoft.com/en-us/library/3stwxh95.aspx

http://www.codeguru.com/cpp/com-tech/atl/misc/article.php/c29

希望这可以帮助。

Responding to your comment: Yes. If you want to expose Automation Compatible interfaces, i.e. those that can be consumed by VB, C# and script languages, each object must be exposed as a COM interface. Also if you are going to store CComPtr<> in a stl list, make sure you use the CAdapt<> wrapper on them.

于 2009-02-24T18:57:45.077 回答