views:

202

answers:

1

I would like to expose an ATL COM collection of CMainClass objects such that it can be accessed by a C#, VB, or C++ client.

I don't have a problem setting up the collection itself, but I don't know how to allow the COM clients access to classes A, B, and C. Should I make A, B, & C COM objects with the ones containing a std::list<> each ATL collections in their own right?

Is there an easier way to do this?!?!

Thanks, PaulH

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_;
};
+2  A: 

Google for implementing IEnumVARIANT in ATL.

Here are some promising links.

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

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

Hope this helps.

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.

m-sharp
So, unless I misunderstood those examples, it looks like the answer is "yes", each class does need to be a COM object and the ones with std::list<> members need to be COM collections.
PaulH