Wednesday, June 10, 2009

How to avoid auto string conversions in Visual Basic

When visual basic programs call outside sources like C++ DLL files, visual basic automatically converts Unicode strings into ASCII strings. After the outside function completes its task, visual basic will convert the ASCII string back into Unicode format. Sometimes the auto conversion done by visual basic can be a problem because programmers may want to keep the string in Unicode format. In order to get around the conversion, programmers should use byte arrays instead of strings.

bytearray() = mystring

The above tip can be very useful when programmers need to keep the string in Unicode format. Some windows API functions require Unicode strings to be passed in order for them to work. Hopefully Microsoft will eventually add an extra feature to allow programers to decide on the conversion process without a hack.

No comments:

Post a Comment