Microsoft KB Archive/138071

= INFO: Strings Passed to DLLs in Variants Aren't Converted to ANSI =

Article ID: 138071

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



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.

Additional query words: 4.00 vb4win vb432

Keywords: kbinfo KB138071

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.