With this compendium of best practices, sophisticated techniques, and valuable utilities, VB programmers will gain a deeper understanding of VB's inner workings and be able to extend its object-oriented capabilities.
Table of Contents
Foreword xiii
Preface xvii
1 Building Blocks 1
Phantom Pointers 2
Living Pointers 3
VBoost Objects 9
2 Leveraging Arrays 11
Array Descriptors 12
Reading Array Variables 16
Writing to Array Variables 19
Array Options: Beyond Fixed or Variable Size 27
Miscellaneous Tips for Using Arrays 37
3 IUnknown: An Unknown Quantity 41
VB and IUnknown 43
Declaring IUnknown and Calling Its Functions 48
4 Binding Functions to Objects 53
When are objects bound to? 56
Name Binding at Runtime 60
VTable-Binding Custom Control Interfaces 65
5 Object Design Constructs 73
Abstraction with Implements 75
Pluggability of Calling Code 78
Implements and Implementation Reuse 81
Aggregation 89
6 Circular References 101
Intermediate Object Solutions 105
Weak References and Collections 110
Transferring Object Ownership 111
Hierarchical Object Models 112
7 External Object Creation 119
Object Creation with Class Factories 121
Loading DLL Objects Directly 125
Custom Loading Custom Controls 130
Custom Class Objects 138
8 Lightweight COM Objects 143
Lightweight Basics 144
Termination Code on Structures 153
LastIID Lightweight 156
ArrayOwner Lightweight 158
Where's the Interface? 161
To Err or Not to Err 162
Returning Errors from Lightweights 165
Aggregating Lightweight Objects 173
Coding the QueryInterface Function 178
9 Large Systems of Objects 183
Using a Fixed-Size Memory Manager 186
Scribble Sample 188
10 VB Objects and the Running Object Table 203
Registering VB Objects with The ROT 205
ROTHook Implementation Details 211
11 Calling Function Pointers 227
Sample: Calling DllRegisterServer 231
Sample: QuickSort, Once and for All 235
Function Pointers in VB for Alpha 239
Stack Allocation 241
Generating Your Own In-Line Assembly 247
Pointers to Class Functions 255
Using CDECL Functions 258
12 Overriding Functions 261
Cooperative Redirection 262
Interface Wrapping 265
Thinner Interface Wrapping 272
Wrapping Issues 276
13 Threads in VB 279
Thread Local Storage 281
Can You Avoid the Marshaling Overhead? 283
To Thread or Not to Thread 283
Creating Threads in a Client EXE 286
Coordinated Gate-Crashing in STA Apartments 307
Creating Worker Threads in DLLs 310
14 Strings in VB 357
UNICODE Conversions 360
String Allocation 363
Strings as Numbers 369
15 Type Libraries and VB 379
VB-Generated Type Libraries 380
VB-Friendly Custom Type Libraries 387
Binary Compatibility 410
Post-Build Type Library Modifications 417
16 Controlling Windows 421
Subclassing 423
Custom Window Creation 433
Windowless Controls 443
Appendix: VBoost Reference 449
Assignment and Arithmetic Functions 451
Memory Allocation Objects 457
Aggregation Functions 459
Index 477