dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: what is ANY ?

  1. #1
    Guest

    what is ANY ?

    When declaring an API procedure declaration as taking a parameter of type
    ANY, what is passed? The address of the variable?

    I've only found one brief mention of this in the MSDN library.

    Can one pass a string to an API by its address via a Long parameter?

    Thanks very much.



  2. #2
    bob butler Guest

    Re: what is ANY ?

    <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > When declaring an API procedure declaration as taking a parameter of type
    > ANY, what is passed? The address of the variable?


    That depends on whether you use ByRef or ByVal in the declare and in the
    line that calls the function. "As Any" tells VB not to do any type checking
    on that argument so you can call it passing a numeric or a string. If you
    use ByVal on a numeric value then the value is sent, otherwise the address
    is sent. If you use ByVal on a string VB converts the string from Unicode
    and passes the address of this temporary ascii string -- on return the
    process is reversed. Using ByRef with a string passes the address of the VB
    BSTR and that is only OK if the routine is specifically designed to work
    with BSTRs.

    > I've only found one brief mention of this in the MSDN library.
    >
    > Can one pass a string to an API by its address via a Long parameter?


    Yes, but you'd need to use the undocumented VarPtr/StrPtr functions and
    probably convert it yourself. You'd do better using Any or String and using
    ByVal on the parameter to get VB to handle it for you.




  3. #3
    bob butler Guest

    Re: what is ANY ?

    <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > When declaring an API procedure declaration as taking a parameter of type
    > ANY, what is passed? The address of the variable?


    That depends on whether you use ByRef or ByVal in the declare and in the
    line that calls the function. "As Any" tells VB not to do any type checking
    on that argument so you can call it passing a numeric or a string. If you
    use ByVal on a numeric value then the value is sent, otherwise the address
    is sent. If you use ByVal on a string VB converts the string from Unicode
    and passes the address of this temporary ascii string -- on return the
    process is reversed. Using ByRef with a string passes the address of the VB
    BSTR and that is only OK if the routine is specifically designed to work
    with BSTRs.

    > I've only found one brief mention of this in the MSDN library.
    >
    > Can one pass a string to an API by its address via a Long parameter?


    Yes, but you'd need to use the undocumented VarPtr/StrPtr functions and
    probably convert it yourself. You'd do better using Any or String and using
    ByVal on the parameter to get VB to handle it for you.




  4. #4
    Mark Alexander Bertenshaw Guest

    Re: what is ANY ?

    Bob -

    When using my imaginary declare:

    Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As Long

    I cannot set pass anything other than String via the Value parameter. Are
    you sure this isn't its only use?

    Thanks,

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    PrimeResponse
    Brentford
    UK

    "bob butler" <butlerbob@my-Deja.com> wrote in message
    news:39d4a3d2$1@news.devx.com...
    > <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > > When declaring an API procedure declaration as taking a parameter of

    type
    > > ANY, what is passed? The address of the variable?

    >
    > That depends on whether you use ByRef or ByVal in the declare and in the
    > line that calls the function. "As Any" tells VB not to do any type

    checking
    > on that argument so you can call it passing a numeric or a string. If you
    > use ByVal on a numeric value then the value is sent, otherwise the address
    > is sent. If you use ByVal on a string VB converts the string from Unicode
    > and passes the address of this temporary ascii string -- on return the
    > process is reversed. Using ByRef with a string passes the address of the

    VB
    > BSTR and that is only OK if the routine is specifically designed to work
    > with BSTRs.
    >
    > > I've only found one brief mention of this in the MSDN library.
    > >
    > > Can one pass a string to an API by its address via a Long parameter?

    >
    > Yes, but you'd need to use the undocumented VarPtr/StrPtr functions and
    > probably convert it yourself. You'd do better using Any or String and

    using
    > ByVal on the parameter to get VB to handle it for you.
    >
    >
    >




  5. #5
    Mark Alexander Bertenshaw Guest

    Re: what is ANY ?

    Bob -

    When using my imaginary declare:

    Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As Long

    I cannot set pass anything other than String via the Value parameter. Are
    you sure this isn't its only use?

    Thanks,

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    PrimeResponse
    Brentford
    UK

    "bob butler" <butlerbob@my-Deja.com> wrote in message
    news:39d4a3d2$1@news.devx.com...
    > <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > > When declaring an API procedure declaration as taking a parameter of

    type
    > > ANY, what is passed? The address of the variable?

    >
    > That depends on whether you use ByRef or ByVal in the declare and in the
    > line that calls the function. "As Any" tells VB not to do any type

    checking
    > on that argument so you can call it passing a numeric or a string. If you
    > use ByVal on a numeric value then the value is sent, otherwise the address
    > is sent. If you use ByVal on a string VB converts the string from Unicode
    > and passes the address of this temporary ascii string -- on return the
    > process is reversed. Using ByRef with a string passes the address of the

    VB
    > BSTR and that is only OK if the routine is specifically designed to work
    > with BSTRs.
    >
    > > I've only found one brief mention of this in the MSDN library.
    > >
    > > Can one pass a string to an API by its address via a Long parameter?

    >
    > Yes, but you'd need to use the undocumented VarPtr/StrPtr functions and
    > probably convert it yourself. You'd do better using Any or String and

    using
    > ByVal on the parameter to get VB to handle it for you.
    >
    >
    >




  6. #6
    Michael \(michka\) Kaplan Guest

    Re: what is ANY ?

    You can pass any type of variable to ANY..... Thats why its called ANY.

    This assumes that the dll export will accept any param type.

    --
    MichKa

    random junk of dubious value at the
    multilingual http://www.trigeminal.com/ and
    a new book on internationalization in VB at
    http://www.i18nWithVB.com/

    "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
    news:39d54d56@news.devx.com...
    > Bob -
    >
    > When using my imaginary declare:
    >
    > Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As Long
    >
    > I cannot set pass anything other than String via the Value parameter. Are
    > you sure this isn't its only use?
    >
    > Thanks,
    >
    > --
    > Mark Alexander Bertenshaw
    > Programmer/Analyst
    > PrimeResponse
    > Brentford
    > UK
    >
    > "bob butler" <butlerbob@my-Deja.com> wrote in message
    > news:39d4a3d2$1@news.devx.com...
    > > <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > > > When declaring an API procedure declaration as taking a parameter of

    > type
    > > > ANY, what is passed? The address of the variable?

    > >
    > > That depends on whether you use ByRef or ByVal in the declare and in the
    > > line that calls the function. "As Any" tells VB not to do any type

    > checking
    > > on that argument so you can call it passing a numeric or a string. If

    you
    > > use ByVal on a numeric value then the value is sent, otherwise the

    address
    > > is sent. If you use ByVal on a string VB converts the string from

    Unicode
    > > and passes the address of this temporary ascii string -- on return the
    > > process is reversed. Using ByRef with a string passes the address of

    the
    > VB
    > > BSTR and that is only OK if the routine is specifically designed to work
    > > with BSTRs.
    > >
    > > > I've only found one brief mention of this in the MSDN library.
    > > >
    > > > Can one pass a string to an API by its address via a Long parameter?

    > >
    > > Yes, but you'd need to use the undocumented VarPtr/StrPtr functions and
    > > probably convert it yourself. You'd do better using Any or String and

    > using
    > > ByVal on the parameter to get VB to handle it for you.
    > >
    > >
    > >

    >
    >




  7. #7
    Michael \(michka\) Kaplan Guest

    Re: what is ANY ?

    You can pass any type of variable to ANY..... Thats why its called ANY.

    This assumes that the dll export will accept any param type.

    --
    MichKa

    random junk of dubious value at the
    multilingual http://www.trigeminal.com/ and
    a new book on internationalization in VB at
    http://www.i18nWithVB.com/

    "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
    news:39d54d56@news.devx.com...
    > Bob -
    >
    > When using my imaginary declare:
    >
    > Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As Long
    >
    > I cannot set pass anything other than String via the Value parameter. Are
    > you sure this isn't its only use?
    >
    > Thanks,
    >
    > --
    > Mark Alexander Bertenshaw
    > Programmer/Analyst
    > PrimeResponse
    > Brentford
    > UK
    >
    > "bob butler" <butlerbob@my-Deja.com> wrote in message
    > news:39d4a3d2$1@news.devx.com...
    > > <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > > > When declaring an API procedure declaration as taking a parameter of

    > type
    > > > ANY, what is passed? The address of the variable?

    > >
    > > That depends on whether you use ByRef or ByVal in the declare and in the
    > > line that calls the function. "As Any" tells VB not to do any type

    > checking
    > > on that argument so you can call it passing a numeric or a string. If

    you
    > > use ByVal on a numeric value then the value is sent, otherwise the

    address
    > > is sent. If you use ByVal on a string VB converts the string from

    Unicode
    > > and passes the address of this temporary ascii string -- on return the
    > > process is reversed. Using ByRef with a string passes the address of

    the
    > VB
    > > BSTR and that is only OK if the routine is specifically designed to work
    > > with BSTRs.
    > >
    > > > I've only found one brief mention of this in the MSDN library.
    > > >
    > > > Can one pass a string to an API by its address via a Long parameter?

    > >
    > > Yes, but you'd need to use the undocumented VarPtr/StrPtr functions and
    > > probably convert it yourself. You'd do better using Any or String and

    > using
    > > ByVal on the parameter to get VB to handle it for you.
    > >
    > >
    > >

    >
    >




  8. #8
    Mark Alexander Bertenshaw Guest

    Re: what is ANY ?

    Michael -

    In that case, why can't I do:


    MYThang 345


    without getting a Type Mismatch?

    I'm using VB5 SP3.

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    PrimeResponse
    Brentford
    UK

    "Michael (michka) Kaplan" <former_mvp@spamfree.trigeminal.nospam.com> wrote
    in message news:39d5545c$1@news.devx.com...
    > You can pass any type of variable to ANY..... Thats why its called ANY.
    >
    > This assumes that the dll export will accept any param type.
    >
    > --
    > MichKa
    >
    > random junk of dubious value at the
    > multilingual http://www.trigeminal.com/ and
    > a new book on internationalization in VB at
    > http://www.i18nWithVB.com/
    >
    > "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
    > news:39d54d56@news.devx.com...
    > > Bob -
    > >
    > > When using my imaginary declare:
    > >
    > > Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As

    Long
    > >
    > > I cannot set pass anything other than String via the Value parameter.

    Are
    > > you sure this isn't its only use?
    > >
    > > Thanks,
    > >
    > > --
    > > Mark Alexander Bertenshaw
    > > Programmer/Analyst
    > > PrimeResponse
    > > Brentford
    > > UK
    > >
    > > "bob butler" <butlerbob@my-Deja.com> wrote in message
    > > news:39d4a3d2$1@news.devx.com...
    > > > <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > > > > When declaring an API procedure declaration as taking a parameter of

    > > type
    > > > > ANY, what is passed? The address of the variable?
    > > >
    > > > That depends on whether you use ByRef or ByVal in the declare and in

    the
    > > > line that calls the function. "As Any" tells VB not to do any type

    > > checking
    > > > on that argument so you can call it passing a numeric or a string. If

    > you
    > > > use ByVal on a numeric value then the value is sent, otherwise the

    > address
    > > > is sent. If you use ByVal on a string VB converts the string from

    > Unicode
    > > > and passes the address of this temporary ascii string -- on return the
    > > > process is reversed. Using ByRef with a string passes the address of

    > the
    > > VB
    > > > BSTR and that is only OK if the routine is specifically designed to

    work
    > > > with BSTRs.
    > > >
    > > > > I've only found one brief mention of this in the MSDN library.
    > > > >
    > > > > Can one pass a string to an API by its address via a Long parameter?
    > > >
    > > > Yes, but you'd need to use the undocumented VarPtr/StrPtr functions

    and
    > > > probably convert it yourself. You'd do better using Any or String and

    > > using
    > > > ByVal on the parameter to get VB to handle it for you.
    > > >
    > > >
    > > >

    > >
    > >

    >
    >




  9. #9
    Mark Alexander Bertenshaw Guest

    Re: what is ANY ?

    Michael -

    In that case, why can't I do:


    MYThang 345


    without getting a Type Mismatch?

    I'm using VB5 SP3.

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    PrimeResponse
    Brentford
    UK

    "Michael (michka) Kaplan" <former_mvp@spamfree.trigeminal.nospam.com> wrote
    in message news:39d5545c$1@news.devx.com...
    > You can pass any type of variable to ANY..... Thats why its called ANY.
    >
    > This assumes that the dll export will accept any param type.
    >
    > --
    > MichKa
    >
    > random junk of dubious value at the
    > multilingual http://www.trigeminal.com/ and
    > a new book on internationalization in VB at
    > http://www.i18nWithVB.com/
    >
    > "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
    > news:39d54d56@news.devx.com...
    > > Bob -
    > >
    > > When using my imaginary declare:
    > >
    > > Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As

    Long
    > >
    > > I cannot set pass anything other than String via the Value parameter.

    Are
    > > you sure this isn't its only use?
    > >
    > > Thanks,
    > >
    > > --
    > > Mark Alexander Bertenshaw
    > > Programmer/Analyst
    > > PrimeResponse
    > > Brentford
    > > UK
    > >
    > > "bob butler" <butlerbob@my-Deja.com> wrote in message
    > > news:39d4a3d2$1@news.devx.com...
    > > > <x@x.x> wrote in message news:39d4a16c$1@news.devx.com...
    > > > > When declaring an API procedure declaration as taking a parameter of

    > > type
    > > > > ANY, what is passed? The address of the variable?
    > > >
    > > > That depends on whether you use ByRef or ByVal in the declare and in

    the
    > > > line that calls the function. "As Any" tells VB not to do any type

    > > checking
    > > > on that argument so you can call it passing a numeric or a string. If

    > you
    > > > use ByVal on a numeric value then the value is sent, otherwise the

    > address
    > > > is sent. If you use ByVal on a string VB converts the string from

    > Unicode
    > > > and passes the address of this temporary ascii string -- on return the
    > > > process is reversed. Using ByRef with a string passes the address of

    > the
    > > VB
    > > > BSTR and that is only OK if the routine is specifically designed to

    work
    > > > with BSTRs.
    > > >
    > > > > I've only found one brief mention of this in the MSDN library.
    > > > >
    > > > > Can one pass a string to an API by its address via a Long parameter?
    > > >
    > > > Yes, but you'd need to use the undocumented VarPtr/StrPtr functions

    and
    > > > probably convert it yourself. You'd do better using Any or String and

    > > using
    > > > ByVal on the parameter to get VB to handle it for you.
    > > >
    > > >
    > > >

    > >
    > >

    >
    >




  10. #10
    bob butler Guest

    Re: what is ANY ?

    Mark Alexander Bertenshaw <mark.bertenshaw@virgin.net> wrote in message
    news:39d54d56@news.devx.com...
    > Bob -
    >
    > When using my imaginary declare:
    >
    > Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As Long
    >
    > I cannot set pass anything other than String via the Value parameter. Are
    > you sure this isn't its only use?


    With "ByVal Value As Any" you can pass a long (which puts the actual value
    on the stack) or a string (which puts the address of the ascii version of
    the string on the stack). Since the stack is composed of 32-bit integers
    the value you pass has to match that type even though you say "as any". Use
    CLng to pass a 16-bit integer or other numeric types.

    If you made it "ByRef Value As Any" then you could use any VB type since
    only the address of the value would be put on the stack for the call.
    Addresses are all 32-bit integers so they all fit. Of course, for a String
    that means you send the address of the BSTR version and most API calls do
    not work correctly with them.





  11. #11
    bob butler Guest

    Re: what is ANY ?

    Mark Alexander Bertenshaw <mark.bertenshaw@virgin.net> wrote in message
    news:39d54d56@news.devx.com...
    > Bob -
    >
    > When using my imaginary declare:
    >
    > Private Declare Function MYThang Lib "oojah" (ByVal Value As Any) As Long
    >
    > I cannot set pass anything other than String via the Value parameter. Are
    > you sure this isn't its only use?


    With "ByVal Value As Any" you can pass a long (which puts the actual value
    on the stack) or a string (which puts the address of the ascii version of
    the string on the stack). Since the stack is composed of 32-bit integers
    the value you pass has to match that type even though you say "as any". Use
    CLng to pass a 16-bit integer or other numeric types.

    If you made it "ByRef Value As Any" then you could use any VB type since
    only the address of the value would be put on the stack for the call.
    Addresses are all 32-bit integers so they all fit. Of course, for a String
    that means you send the address of the BSTR version and most API calls do
    not work correctly with them.





  12. #12
    bob butler Guest

    Re: what is ANY ?

    Mark Alexander Bertenshaw <mark.bertenshaw@virgin.net> wrote in message
    news:39d5fb3f@news.devx.com...
    > Michael -
    >
    > In that case, why can't I do:
    >
    >
    > MYThang 345
    >
    >
    > without getting a Type Mismatch?


    345 fits in a 16-bit integer and that does not match the 32-bit integer
    required for the stack...
    x=mythang(345&)
    x=mythang(clng(345))




  13. #13
    bob butler Guest

    Re: what is ANY ?

    Mark Alexander Bertenshaw <mark.bertenshaw@virgin.net> wrote in message
    news:39d5fb3f@news.devx.com...
    > Michael -
    >
    > In that case, why can't I do:
    >
    >
    > MYThang 345
    >
    >
    > without getting a Type Mismatch?


    345 fits in a 16-bit integer and that does not match the 32-bit integer
    required for the stack...
    x=mythang(345&)
    x=mythang(clng(345))




  14. #14
    Mark Alexander Bertenshaw Guest

    Re: what is ANY ?


    bob -

    >> In that case, why can't I do:
    >>
    >> MYThang 345
    >>
    >> without getting a Type Mismatch?

    >
    >345 fits in a 16-bit integer and that does not match the 32-bit integer
    >required for the stack...
    >x=mythang(345&)
    >x=mythang(clng(345))


    Thanks!


    -------------------------
    Mark Alexander Bertenshaw
    Programmer/Analyst
    Prime Response
    Brentford
    UK


  15. #15
    Mark Alexander Bertenshaw Guest

    Re: what is ANY ?


    bob -

    >> In that case, why can't I do:
    >>
    >> MYThang 345
    >>
    >> without getting a Type Mismatch?

    >
    >345 fits in a 16-bit integer and that does not match the 32-bit integer
    >required for the stack...
    >x=mythang(345&)
    >x=mythang(clng(345))


    Thanks!


    -------------------------
    Mark Alexander Bertenshaw
    Programmer/Analyst
    Prime Response
    Brentford
    UK


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