One significant difference between 16-bit and 32-bit environments is in how string data is stored and manipulated. Visual Basic in Microsoft Excel uses ANSI (American National Standards Institute) characters (a single byte represents each character) to store and manipulate strings in both 16- and 32-bit versions. Conversely, 32-bit OLE Automation and the 32-bit OLE 2 API use Unicode (two bytes represent each character) to store and manipulate strings.
Environment |
Character Set | |
Windows 3.1 |
ANSI | |
Windows95 API |
ANSI | |
32Bit Object Libraries |
Unicode | |
Windows NT API |
Unicode | |
OLE Automation in Windows NT |
Unicode | |
OLE Automation in Windows95 |
Unicode |
When you pass string data from Visual Basic in Microsoft Excel, the data uses ANSI characters. You can leave the strings in ANSI format if you are simply passing them back to Microsoft Excel or calling a Windows 95 system function, but you may need Unicode characters if you use OLE Automation or you call an OLE 2 API function. You can use the MultiByteToWideChar Win32 API to convert an ANSI string to Unicode, and the WideCharToMultiByte API to convert a Unicode string to ANSI.
In addition, because Microsoft Excel uses ANSI characters in BSTR variables, you cannot use the standard OLE string allocation and reallocation functions (these functions now create Unicode strings). Two new functions, SysAllocStringByteLen and SysStringByteLen, exist to operate on single-byte character strings.