IEnumVariant


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: IEnumVariant

  1. #1
    Michael Culley Guest

    IEnumVariant


    Hi Everybody,

    Does anyone know about creating your own IEnumVariant object.

    I have downloaded a sample but have a few questions. This sample is an adaption
    from Hardcore Visual Basic.

    1) Why does IEnumVARIANT_Next need to go in a standard module? Is this just
    to have access to the HResult?

    2) Why does the error object need to be mapped to the HResult?

    3) Does IEnumVARIANT_Reset, IEnumVARIANT_Skip or IEnumVARIANT_Clone ever
    get called?

    4) Why does IEnumVARIANT_Next seam to want an array of objects? I have been
    returning one only and it seams to work fine.

    Thanks in advance

    Michael Culley

  2. #2
    Anthony Jones Guest

    Re: IEnumVariant

    Michael,

    >>

    1) Why does IEnumVARIANT_Next need to go in a standard module? Is this just
    to have access to the HResult?
    <<

    Yep, in order to return S_FALSE when there are no more items to return.

    >>

    2) Why does the error object need to be mapped to the HResult?
    <<

    Because that is what VB does for you when returning from a method call on
    class. Since we have replaced the VB generated function for that method
    with our own in the vtable it is up to us to make sure than any error is
    passed through HRESULT return value. In fact as noted above the whole point
    of this exercise was to take charge of the HRESULT. Bear in mind that the
    caller may simply be testing the HRESULT returned to see if an error has
    occured.

    >>

    3) Does IEnumVARIANT_Reset, IEnumVARIANT_Skip or IEnumVARIANT_Clone ever
    get called?


    4) Why does IEnumVARIANT_Next seam to want an array of objects? I have been
    returning one only and it seams to work fine.
    <<

    These two questions are closely related. The IEnum<XX> set of interfaces
    define a pattern for an enumeration service. Different clients of that
    service may choose to operate in various ways. Not all will use the full
    set of features provided by the service.

    VB's For Each construct represents a client of an enumeration service. As
    can be seen by observation this client code (built into VB's Runtime) seems
    only to keep calling Next asking for just 1 item until Next returns
    S_FALSE.

    However other client code may choose to request mutliple items at a time,
    decide to skip items, may want to reset the enumeration to the beginning,
    may want to start a secondary enumeration based on the first. All these
    features are supported by the enumeration interfaces.

    If you are positive the only client of your enumerator is going to be For
    Each then you might get away with taking some short-cuts. Personally I
    think that would be a bad idea, implementing an interface means adhereing
    to a contract for expected behaviour.


    --
    Anthony Jones
    Nuesoft Ltd




  3. #3
    Eduardo A. Morcillo Guest

    Re: IEnumVariant

    > 1) Why does IEnumVARIANT_Next need to go in a standard module? Is this
    just
    > to have access to the HResult?


    Yes. Also the whole object can be on a standard module (check out the
    FastCollection class on my site).

    > 2) Why does the error object need to be mapped to the HResult?


    The Err object can't be used in the Next method because you have to return
    S_FALSE (when there's no more items and the Err cannot return that value.

    > 3) Does IEnumVARIANT_Reset, IEnumVARIANT_Skip or IEnumVARIANT_Clone ever
    > get called?


    Not in VB.

    > 4) Why does IEnumVARIANT_Next seam to want an array of objects? I have

    been
    > returning one only and it seams to work fine.


    That's the standard IEnumxxxx behavior, but the Next method can return any
    number of items (not more than the requested). BTW, For...Each only gets one
    at a time.

    --
    Eduardo A. Morcillo
    http://www.domaindlx.com/e_morcillo



  4. #4
    Michael Culley Guest

    Re: IEnumVariant


    >Yes. Also the whole object can be on a standard module (check out the
    >FastCollection class on my site).


    Turn a standard module into a com object, very interesting.

    Michael Culley

  5. #5
    Michael Culley Guest

    Re: IEnumVariant


    Personally I
    >think that would be a bad idea


    I hadn't really thought about other clients, but I guess it is possible that
    someone might take my dll and use it in delphi etc.

    Can you explain more about the error mapping? How does the HResult relate
    to the error object.

    Michael Culley

    "Anthony Jones" <yadayadayada@msn.com> wrote:
    >Michael,
    >
    >>>

    >1) Why does IEnumVARIANT_Next need to go in a standard module? Is this just
    >to have access to the HResult?
    ><<
    >
    >Yep, in order to return S_FALSE when there are no more items to return.
    >
    >>>

    >2) Why does the error object need to be mapped to the HResult?
    ><<
    >
    >Because that is what VB does for you when returning from a method call on
    >class. Since we have replaced the VB generated function for that method
    >with our own in the vtable it is up to us to make sure than any error is
    >passed through HRESULT return value. In fact as noted above the whole point
    >of this exercise was to take charge of the HRESULT. Bear in mind that the
    >caller may simply be testing the HRESULT returned to see if an error has
    >occured.
    >
    >>>

    >3) Does IEnumVARIANT_Reset, IEnumVARIANT_Skip or IEnumVARIANT_Clone ever
    >get called?
    >
    >
    >4) Why does IEnumVARIANT_Next seam to want an array of objects? I have been
    >returning one only and it seams to work fine.
    ><<
    >
    >These two questions are closely related. The IEnum<XX> set of interfaces
    >define a pattern for an enumeration service. Different clients of that
    >service may choose to operate in various ways. Not all will use the full
    >set of features provided by the service.
    >
    >VB's For Each construct represents a client of an enumeration service.

    As
    >can be seen by observation this client code (built into VB's Runtime) seems
    >only to keep calling Next asking for just 1 item until Next returns
    >S_FALSE.
    >
    >However other client code may choose to request mutliple items at a time,
    >decide to skip items, may want to reset the enumeration to the beginning,
    >may want to start a secondary enumeration based on the first. All these
    >features are supported by the enumeration interfaces.
    >
    >If you are positive the only client of your enumerator is going to be For
    >Each then you might get away with taking some short-cuts. Personally I
    >think that would be a bad idea, implementing an interface means adhereing
    >to a contract for expected behaviour.
    >
    >
    >--
    >Anthony Jones
    >Nuesoft Ltd
    >
    >
    >



  6. #6
    Guest

    Re: IEnumVariant


    Sounds like Matthew Curland-inspired ideas ("Advanced Visual Basic", not to
    be confused with "Advanced Microsoft Visual Basic", which takes the opposite
    track of loving Variants and the like).

    I would love to see any material on the topic of implementing IENUMVariant
    behaviour in a VB class.

    I have long wanted to give my data structure objects for each ... in ...
    support without wrapping a collection object.

    VB seems to have a hard-coded prejudice against allowing the implementation
    of certain interfaces, such as IENUMVariant, in a class. Surely there is a
    way.

    I am partial to a stable, non-hacked way of doing things myself.

    Web sites, explanations?


    "Michael Culley" <m_culley@one.net.au> wrote in message
    news:39a3241f$1@news.devx.com...
    >
    > >Yes. Also the whole object can be on a standard module (check out the
    > >FastCollection class on my site).

    >
    > Turn a standard module into a com object, very interesting.
    >
    > Michael Culley




  7. #7
    Colin McGuigan Guest

    Re: IEnumVariant

    <x@x.x> wrote in message news:39bfa8d0@news.devx.com...
    >
    > Sounds like Matthew Curland-inspired ideas ("Advanced Visual Basic", not

    to
    > be confused with "Advanced Microsoft Visual Basic", which takes the

    opposite
    > track of loving Variants and the like).
    >
    > I would love to see any material on the topic of implementing IENUMVariant
    > behaviour in a VB class.
    >
    > I have long wanted to give my data structure objects for each ... in ...
    > support without wrapping a collection object.
    >
    > VB seems to have a hard-coded prejudice against allowing the

    implementation
    > of certain interfaces, such as IENUMVariant, in a class. Surely there is

    a
    > way.
    >
    > I am partial to a stable, non-hacked way of doing things myself.
    >
    > Web sites, explanations?


    Matthew Curland wrote an article about this in a....1999(?) issue of VBPJ.
    It's also covered by Bruce McKinney in Hardcore Visual Basic, which can be
    found and downloaded on the web.

    The only 'hack' required is that you have to use a type library to get a VB
    friendly version of IEnumVariant. Since type libraries don't require
    distribution, I don't see this one as a biggy.

    --
    Colin McGuigan




  8. #8
    Anthony Jones Guest

    Re: IEnumVariant

    >The only 'hack' required

    <Chad image goes here>

    Wot no vtable replacement :-)

    --
    Anthony Jones
    Nuesoft Ltd




  9. #9
    Michael Culley Guest

    Re: IEnumVariant


    This was the hacky part, not the type library.



    "Anthony Jones" <yadayadayada@msn.com> wrote:
    >>The only 'hack' required

    >
    ><Chad image goes here>
    >
    >Wot no vtable replacement :-)
    >
    >--
    >Anthony Jones
    >Nuesoft Ltd
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center