INFO: Strings Passed to DLLs in Variants Aren't Converted to ANSI (138071)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
This article was previously published under Q138071 SUMMARY
On Win32 Operating systems, if a variant containing a UNICODE string is
passed to a DLL, Visual Basic version 4.0 (32-bit version) does not
automatically convert it to ANSI, as it would a UNICODE string that is
passed directly.
MORE INFORMATION
Visual Basic version 4.0 (32-bit version) stores strings as UNICODE
internally. So, if you assign a string to a variant in Visual Basic version
4.0 (32-bit), it will be stored as UNICODE. Now, if you pass this to a
32-bit DLL function either by reference or by value, Visual Basic will not
automatically convert the string contained in the variant to ANSI. If you
are building a UNICODE DLL or using a pre-existing UNICODE DLL, this is not
a problem. However, for custom ANSI DLLs, you will have to convert the
string to ANSI yourself, using the WideCharToMultiByte Windows API function
inside the DLL, in order to actually use the string meaningfully. For
pre-built ANSI DLLs, you must convert the Visual Basic version 4.0 UNICODE
string to ANSI, using the StrConv function, assign it to the Variant, and
then pass it to the DLL. You could use the latter approach for your own
custom ANSI DLLs too.
Modification Type: | Major | Last Reviewed: | 12/9/2003 |
---|
Keywords: | kbinfo KB138071 |
---|
|