Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / August 2004

Tip: Looking for answers? Try searching our database.

How to treat GetEnumerator(); from C++ COM's IEnumVARIANT

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Juan Dent - 18 Aug 2004 22:45 GMT
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?

Signature

Thanks in advance,

Juan Dent, M.Sc.

Mattias Sj?gren - 19 Aug 2004 10:59 GMT
Juan,

>What am I doing wrong?

You can't cast the IUnknown pointer returned by GetIUnknownForObject()
to IEnumVARIANT* like that. If anything, you should QueryInterface()
for it. But managed enumerators don't even implement IEnumVARIANT.

Try using the
System.Runtime.InteropServices.CustomMarshalers.EnumVariantViewOfEnumerator
class in CustomMarshalers.dll instead. It provides an IEnumVARIANT
wrapper around an IEnumerator object.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.