Juan Dent
2004-08-18 21:45:02 UTC
Hi,
I have an interface in C# like so:
public interface ICollectionJD
{
// support for enumeration
[DispId(-4), Description("property _NewEnum")]
IEnumerator GetEnumerator();
}
I am implementing a wrapper for this managed code in C++, where I declare
the interface like so:
__interface ICollection : IDispatch
{
[id(-4), helpstring("property _NewEnum")] HRESULT GetEnumerator([out,
retval] IEnumVARIANT** pRetVal);
}
Or like so:
__interface ICollection : IDispatch
{
[propget, id(-4), helpstring("property _NewEnum")] HRESULT _NewEnum([out,
retval] IUnknown** pVal);
}
The coclass in C++ looks like:
class ATL_NO_VTABLE CCollection :
public ICollection
{
private:
gcroot<PropertyDefaultsCollection*> managed;
public:
CCollection()
{
this->managed=new PropertyDefaultsCollection();
}
//...
}
where PropertyDefaultsCollection is a public class in C# that implements the
ICollectionJD interface.
My problem is in the implementation of GetEnumerator(), trying:
STDMETHODIMP CCollection::GetEnumerator(IEnumVARIANT** pVal)
{
IntPtr ptr = IntPtr::Zero;
try
{
IEnumerator* enumerator = managed->GetEnumerator();
ptr = Marshal::GetIUnknownForObject( enumerator );
*pVal = (IEnumVARIANT*)ptr.ToPointer();
return S_OK;
}
catch( Exception * ex)
{
return Marshal::GetHRForException( ex );
}
}
When I call this from a client in VB6, using:
dim o as object
for each o in wrap
'...
next
I get this error:
Runtime error '451':
Property let procedure not defined and property get procedure did not
return an object.
What am I doing wrong?
I have an interface in C# like so:
public interface ICollectionJD
{
// support for enumeration
[DispId(-4), Description("property _NewEnum")]
IEnumerator GetEnumerator();
}
I am implementing a wrapper for this managed code in C++, where I declare
the interface like so:
__interface ICollection : IDispatch
{
[id(-4), helpstring("property _NewEnum")] HRESULT GetEnumerator([out,
retval] IEnumVARIANT** pRetVal);
}
Or like so:
__interface ICollection : IDispatch
{
[propget, id(-4), helpstring("property _NewEnum")] HRESULT _NewEnum([out,
retval] IUnknown** pVal);
}
The coclass in C++ looks like:
class ATL_NO_VTABLE CCollection :
public ICollection
{
private:
gcroot<PropertyDefaultsCollection*> managed;
public:
CCollection()
{
this->managed=new PropertyDefaultsCollection();
}
//...
}
where PropertyDefaultsCollection is a public class in C# that implements the
ICollectionJD interface.
My problem is in the implementation of GetEnumerator(), trying:
STDMETHODIMP CCollection::GetEnumerator(IEnumVARIANT** pVal)
{
IntPtr ptr = IntPtr::Zero;
try
{
IEnumerator* enumerator = managed->GetEnumerator();
ptr = Marshal::GetIUnknownForObject( enumerator );
*pVal = (IEnumVARIANT*)ptr.ToPointer();
return S_OK;
}
catch( Exception * ex)
{
return Marshal::GetHRForException( ex );
}
}
When I call this from a client in VB6, using:
dim o as object
for each o in wrap
'...
next
I get this error:
Runtime error '451':
Property let procedure not defined and property get procedure did not
return an object.
What am I doing wrong?
--
Thanks in advance,
Juan Dent, M.Sc.
Thanks in advance,
Juan Dent, M.Sc.