How to have an interface as a member variable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm new to writing a COM server. I've been looking at various
resources, but I haven't been able to figure out what should be a
simple thing to do. Thanks for your help!

I'm trying to move a C++ class to a COM server. This is the basic idea
(this is obviously a trivial example; it is trimmed to show the
problem):

[ See the two questions buried in comments below ]

class MyData
{
private:
int iVar1;
int iVar2;
// etc....
friend class MyClass;
public:
int GetVar1() const;
int GetVar2() const;
// etc....
};

class MyClass
{
private:
MyData data;

void ChangeData()
{
++data.iVar1;
++data.iVar2;
}
// etc....
public:
const MyData* const GetData() const
{
return &data;
}
};

Now, I've created a COM Server DLL using the the MSVC8 wizard, then I
went to the Class View and created two interfaces (Simple ATL objects).

This created:

class ATL_NO_VTABLE CMyData :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CMyData, &CLSID_MyData>,
public IDispatchImpl<IMyData, &IID_IMyData, &LIBID_myobj, /*wMajor =*/
1, /*wMinor =*/ 0>
{
int iVar1; // I added these by hand
int iVar2;
};

class ATL_NO_VTABLE CMyData :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CMyData, &CLSID_MyData>,
public IDispatchImpl<IMyData, &IID_IMyData, &LIBID_myobj, /*wMajor =*/
1, /*wMinor =*/ 0>
{
private:
// Question: How do I declare the member variable here?
public:
STDMETHOD(GetData)(IMyData ** pVal)
{
// Question: How do I return the data here?
}
};

.



Relevant Pages