DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    How do you convert a C++ string to a VB

    [Originally posted by Tich]

    How do you convert a pointer to a C++ (null terminated) string into a nomal VB string?

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    RE: Convert a C++ string to VB

    [Originally posted by FreeVBCode.com]

    You may find http://support.microsoft.com/support/kb/articles/Q187/9/12.ASP helpful.

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:RE: Convert a C++ string to VB

    [Originally posted by Tich]

    What i realy wanted to do was replace some 'C' code with a piece of VB.ÿ The 'C' code was :-

    // Get a VB string from a text pointer

    STDAPI_(BSTR) GetStringFromLPSTR(LPSTR tptr)
    {
    BSTR rptr;

    char tbuf = '\0';
    ÿ if(!tptr) {
    ÿ ÿ ÿ rptr = SysAllocString((OLECHAR *)&tbuf);
    ÿ ÿ ÿ }
    ÿ else {
    // Why do it by length? Because SysAllocString looks for a double
    // null - which may not be present
    ÿ ÿ ÿ rptr = SysAllocStringByteLen(tptr, lstrlen(tptr));
    ÿ ÿ ÿ }
    //ÿ MessageBox(NULL,(LPSTR)rptr,NULL,0);
    ÿ return(rptr);
    }

    It works fine, but i wanted the functionality within VB (i dont want to have to distribute a seperate 'C' Dll)

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:RE: Convert a C++ string to VB

    [Originally posted by FreeVBCode.com]

    I have added a code example to do this.ÿ See <A HREF = 'http://www.freevbcode.com/ShowCode.Asp?ID=2643'>http://www.freevbcode.com/ShowCode.Asp?ID=2643</A>.

    Note that this example is for Unicode strings.ÿ I don't know if this is what is used in C.ÿ But if it's not, there are also instructions for how to change the code.

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links