DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005

    Visual Basic string is Unicode?

    Hi Everyone.

    I am making a DLL in C++ so as to call it from VB.

    In VB:
    Private Declare Sub test Lib "../testdll.dll" (a as string, b as string) as long

    In C++:
    long __stdcall test(BSTR *a, BSTR *b) {
    return 1;

    When I test the DLL I find that the string passed to it, the variable who receives it is *a, is not a UNICODE string: if you check memory you find a simple ANSI array of characters.

    For Example in VB a = "bob"

    Shows in Memory:

    42 = 'b'
    6F = 'o'
    62 = 'b'
    00 = NULL

    the ANSI of "bob", instead of the UNICODE representation:

    42 = 'b'
    00 = NULL
    6F = 'o'
    00 = NULL
    62 = 'b'
    00 = NULL
    00 = NULL
    00 = NULL

    I would appreciate so much if someone can explain to me this issue.

    After all, strings in VB are not UNICODE?

    Thanks so much.


  2. #2
    Join Date
    Apr 2004
    - I know approx nothing about C (and I plan to keep it that way!) but I can tell you for sure that 32 bit versions of VB do use Unicode strings internally. Any routine that exposes the string to the "external" world first converts the string to ASCII, but internally, they are all Unicode.
    - If you were to use, for example, the CopyMemory API call against a VB string, you would see this very clearly...

  3. #3
    Join Date
    Nov 2003
    Portland, OR
    VB automatically makes an ANSI copy of the string and passes the copy to the DLL. You may use the StrPtr function to work around this behavior: http://vb.mvps.org/tips/varptr.asp
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. string functions in visual basic
    By raja in forum VB Classic
    Replies: 1
    Last Post: 06-07-2002, 03:32 PM
  2. yag's status report - April 4, 2002
    By Yair Alan Griver [MSFT] in forum vb.announcements
    Replies: 0
    Last Post: 04-04-2002, 09:28 PM
  3. YAG's public status report - March 7, 2002
    By Seth Grossman [MSFT] in forum vb.announcements
    Replies: 1
    Last Post: 03-13-2002, 07:32 PM
  4. Replies: 0
    Last Post: 06-22-2000, 07:30 AM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.