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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

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

  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.

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