Hopefully I have the correct newsgroup for this question.
I've developed a very simple COM server in C++ as im trying to learn
COM. The COM server has an array of IUnknown interfaces (MyArray)
where im allowing the user to store COM objects (derived from
IUnknown) via get/put properties.
I have a created a COM object which is derived from IUnknown but when
i come to add the object to my array from C# i get a com exception :
"Unable to cast COM object of type 'MyListClass' to interface type
'IMyList'. This operation failed because the QueryInterface call on
the COM component for the interface with IID "
The functions to add to the array are (it only returns the first
element in the array for now!):
STDMETHODIMP CMyList::get_ArrayItem(LPUNKNOWN * pVal)
{
if (this->m_aUnkArray.size() == 0)
return E_FAIL;
pVal = this->m_aUnkArray.at(0);
return S_OK;
}
STDMETHODIMP CMyList::put_ArrayItem(LPUNKNOWN newVal)
{
this->m_aUnkArray.push_back(&newVal);
return S_OK;
}
The array storing the IUnknowns is a vector:
std::vector <IUnknown**m_aUnkArray;
....and the C# code im using to call the COM object is:
MyCOMServer comServer = new MyCOMServer ;
MyItemClass item1 = new MyItemClass();
item1.Text3 = "andy";
MyListClass list = new DCOMAPPLib.MyListClass();
list.DispArrayItem = item1; <--------
exception occurs here
Is it possible to put/get C# objects to a property which takes
IUnknown as parameter? Any advice on what im doing wrong will be
appreciated.
Thanks,
Andy