contents   index   previous   next



BStrings

 

BStrings are a bit more complex than OLE strings. A BString is an OLE String with a header that contains information about the length of the string. The way BStrings are represented in memory is illustrated in Figure 1.3.

 

BStrings are the strings used by COM/OLE Automation, Visual Basic (including Visual Basic for Applications) and VBScript [01]. A BString is referenced through a handle, which is a pointer to the first character in the string (see Figure 1.4). This is obvious in Fortran or C, because in these languages BStrings are directly manipulated through their handles. On the other hand, Visual Basic does a good job isolating the user from the complexities of OLE automation, so it is not as obvious that the language is still using handles to reference BStrings. However, when you call a Visual Basic procedure with a string argument, the Visual Basic compiler passes a BString handle, rather than the string itself.

 

Although there is nothing to stop you from doing it, you should never manipulate the content of a BString by directly accessing the memory locations where it is stored. BStrings must be handled through the functions and subroutines provided in f90VB. There are also a set of rules you should follow when manipulating BStrings. Again, there is no code in f90VB or COM/OLE Automation that enforces these rules. But if you expect to write well-behaved applications, you should learn and practice these rules by heart.

 

Eight basic rules for manipulating BStrings