-
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.
FededS
-
FedEdS:
- 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...
-
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
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Similar Threads
-
By raja in forum VB Classic
Replies: 1
Last Post: 06-07-2002, 03:32 PM
-
By Yair Alan Griver [MSFT] in forum vb.announcements
Replies: 0
Last Post: 04-04-2002, 09:28 PM
-
By Seth Grossman [MSFT] in forum vb.announcements
Replies: 1
Last Post: 03-13-2002, 07:32 PM
-
By Chandra in forum VB Classic
Replies: 0
Last Post: 06-22-2000, 07:30 AM
-
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
Forum Rules
|
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
|
Bookmarks