DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 4 of 4 FirstFirst ... 234
Results 46 to 47 of 47

Thread: how to use BSTR

  1. #46
    Bill McCarthy Guest

    Re: how to use BSTR


    "Mattias Sjögren" <mattiass.dont.want.spam@hem.passagen.se> wrote in message
    news:38f4ae6d.20286870@news.devx.com...
    > Damit,
    >
    > >: Yes, but StrPtr sould be similar to passing the string ByVal - it will
    > >: be a BSTR on the C++ side. VarPtr is similar to passing it ByRef,
    > >: giving a BSTR* on the C++ side. Both the *Ptr functions will prevent
    > >: the character conversion though, so it will be "true" Unicode BSTRs,
    > >: not ANSI,
    > >
    > >But his (Mike's) declaration is already ByVal, so I don't know that it

    makes
    > >a difference...

    >
    > What I meant was that StrPtr() gives you a pointer to the character
    > array in memory (BSTR), while VarPtr() gives you a pointer to the
    > string pointer (BSTR*). And this is what you get on the C++ side too,
    > assuming Mike pass this value ByVal to the DLL. If he declares it as
    > ByRef, the result would be BSTR* and BSTR** on the C++ side... uhh..
    > I think I'll shut up now, this is getting more and more confusing :-)
    >


    I'm probably missing the point here, (especially as my knowledge of C++ is
    minimal), but if you want to modify the VB string in the C++ DLL then you
    would have to pass the string ByRef, which by my reckoning would probably be
    the same as passing VarPtr ByVal.
    The VarPtr for the string is a constant (while the variable is in scope),
    and at the VarPtr location is the pointer to the String. IOW. VarPtr is
    equiv of BSTR**. By changing the value at VarPtr location you can point the
    variable to another string etc (don't forget to clean up the old one too)






  2. #47
    Bill McCarthy Guest

    Re: how to use BSTR


    "Mattias Sjögren" <mattiass.dont.want.spam@hem.passagen.se> wrote in message
    news:38f4ae6d.20286870@news.devx.com...
    > Damit,
    >
    > >: Yes, but StrPtr sould be similar to passing the string ByVal - it will
    > >: be a BSTR on the C++ side. VarPtr is similar to passing it ByRef,
    > >: giving a BSTR* on the C++ side. Both the *Ptr functions will prevent
    > >: the character conversion though, so it will be "true" Unicode BSTRs,
    > >: not ANSI,
    > >
    > >But his (Mike's) declaration is already ByVal, so I don't know that it

    makes
    > >a difference...

    >
    > What I meant was that StrPtr() gives you a pointer to the character
    > array in memory (BSTR), while VarPtr() gives you a pointer to the
    > string pointer (BSTR*). And this is what you get on the C++ side too,
    > assuming Mike pass this value ByVal to the DLL. If he declares it as
    > ByRef, the result would be BSTR* and BSTR** on the C++ side... uhh..
    > I think I'll shut up now, this is getting more and more confusing :-)
    >


    I'm probably missing the point here, (especially as my knowledge of C++ is
    minimal), but if you want to modify the VB string in the C++ DLL then you
    would have to pass the string ByRef, which by my reckoning would probably be
    the same as passing VarPtr ByVal.
    The VarPtr for the string is a constant (while the variable is in scope),
    and at the VarPtr location is the pointer to the String. IOW. VarPtr is
    equiv of BSTR**. By changing the value at VarPtr location you can point the
    variable to another string etc (don't forget to clean up the old one too)






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