PART I INTRODUCTION TO UPGRADING
1 Visual Basic .NET Is More Than Visual Basic 6 + 1 3
Why Break Compatibility? 6
Adding New Features 6
Fixing the Language 7
Modernizing the Language 8
It Is Still Visual Basic 8
Expect Subtle Differences 8
Plan for a 95 Percent Automated Upgrade 9
Why Should I Upgrade? 10
New Language Features 10
Windows Forms 14
New Web Development Features 15
Better Development Environment 15
Is Visual Basic Still the Best Choice for Visual Basic Developers? 16
Conclusion 18
2 Visual Basic 6 and Visual Basic .Net: Differences 19
.NET Framework vs. ActiveX 19
.NET Framework 21
Memory Management 22
Type Identity 25
Threading Model 29
Differences in the Development Environment 29
Menu Editor 30
Toolbox 31
Property Browser 32
Tab Layout Editor 33
Forms Packages 34
A Single Standard for Windows Forms 34
Two Forms Packages for the Price of One 35
Language Differences 35
All Subroutine Calls Must Have Parentheses 37
ByVal or ByRef Is Required 38
Is That My Event? 38
Arrays Must Have a Zero-Bound Lower Dimension 39
Fixed-Length Strings Are Not Supported 40
Variant Data Type Is Eliminated 40
Visibility of Variables Declared in Nested Scopes Is Limited 41
Changes in the Debugger 42
No Edit and Continue 42
Cannot Continue After an Error 42
No Repainting in Break Mode 42
Conclusion 43
3 Upgrading Options 45
Upgrading Is Optional 45
Don’t Upgrade 45
Partial Upgrade 46
Complete Upgrade 47
Upgrade with Interoperability 47
Role of the Upgrade Wizard 48
The Upgrade Report 48
Testing 49
Upgrading from Earlier Versions of Visual Basic 49
Selecting Projects to Upgrade 50
Evaluating the Benefits 51
Evaluating the Effort Required 55
Developing the Upgrade Plan 58
Conclusion 59
4 Preparing Your Project for the Upgrade to Visual Basic .NET 61
Why Change Anything? 61
Cleaning Up Legacy Code 62
VarPtr, DefInt, and Other No-Shows 62
DAO and RDO Data Binding 63
Good Visual Basic 6 Coding Practices 64
Variants and Variables 64
Abstraction 66
Early Binding vs. Late Binding vs. Soft Binding 69
Watch Out for Null and Empty 73
Implicit Object Instantiation 74
Conclusion 76
PART II UPGRADING APPLICATIONS
5 Your First Upgrade 79
Upgrade Walkthrough 79
What Just Happened? 85
Language Changes 88
Other Files in Your Project 92
Upgrading Project Groups 94
Using the VB Snippet Upgrade Add-In 98
Upgrading Using the Command Line 99
Conclusion 100
6 Common Tasks in Visual Basic .NET 101
A Guide to Working in Visual Basic .NET 101
Creating a Visual Basic .NET Project 102
Getting to Know the Visual Studio .NET IDE 104
Running Your Project 106
A Quick Introduction to Debugging 107
Miscellaneous Items 108
Handling Build Errors 108
Using the Task List 109
Using Breakpoints 110
References 111
Problem-Solving Techniques 112
Using the System.Diagnostics Library 112
Using CorDbg 113
Simplifying Complex Expressions 114
Conclusion 115
7 Upgrade Wizard Ins and Outs 117
Upgrade Philosophy 117
It’s Your Code 117
Just Make It Work 118
Compatibility Library 119
Upgrade Wizard Capabilities and Limitations 119
Wizard Methodology 119
Project Upgrade 121
Forms and Intrinsic Controls 128
ActiveX Controls and ActiveX References 137
Visual Basic Code 140
Global Objects 145
Class Modules and User Controls 145
Objects for Accessing Data 146
Designers 147
Conclusion 148
8 Errors, Warnings, and Issues 149
The Different Kinds of EWIs 152
Upgrade Issues 152
Upgrade ToDos 153
Run-Time Warnings 154
Design Issues 154
Upgrade Notes and Global Warnings 155
Understanding the Upgrade Report 155
Estimating Fix Time 157
Working with EWIs 159
The Different Upgrade EWIs 160
Upgrade Issues 160
Upgrade ToDos 163
Upgrade Warnings 164
Design Errors 167
Global Warnings 169
Upgrade Notes 170
Which Problems Are Not Detected? 172
Conclusion 174
9 Using Visual Basic 6 with Visual Basic .NET: COM Interop 175
Where COM Interop Comes into Play 177
ActiveX Controls 177
Communication Between a .NET Client and a COM Server Component 177
Communication Between a COM Client and a .NET Server Component 178
Upgrading a Visual Basic 6 Client/Server Application 178
Creating a .NET Client That Talks to a COM Server 180
Debugging Between the Visual Basic .NET Client and Visual Basic 6 Server 182
Exposing a Visual Basic .NET Component to Be Called by a Visual Basic 6 Client 184
Debugging Between the Visual Basic 6 Client and .NET Server 187
Tying It All Together 188
Replacing COM with .NET: Binary Compatibility 189
Indirect Replacement Model 190
Enabling Binary Compatibility in Visual Basic .NET Classes 191
Conclusion 196
PART III GETTING YOUR PROJECT WORKING
10 Ten Common Upgrade Problems 199
Default Properties 199
AddItem and ToString with COM Objects 201
Deterministic Finalization and Garbage Collection 203
Bringing a Little Determinism to the Party 205
Generic Objects (Control/Form/Screen) 206
Dim…As New 207
Sub Main (or Default Form) 208
Font Disparities 209
Bad Constants 212
Drag and Drop 213
Drag and Drop in Visual Basic 6 213
Drag and Drop in Visual Basic .NET 215
Collection Classes 219
Conclusion 222
11 Resolving Issues with Language 223
Language Elements 224
#If…#End If Precompiler Statements 224
Constants and Constant Expressions 224
Control Flow 227
File Functions 232
Types and Type Operations 238
Object Replaces Variant 238
Arrays 242
Structures 245
Making Your Code Thread-Safe 249
Windows API 251
Type Changes 252
As Any No Longer Supported 253
AddressOf Changes 254
Passing User-Defined Types to API Functions 258
ObjPtr and StrPtr Not Supported 261
Conclusion 263
12 Resolving Issues with Forms 265
Similarities in Form Structure 265
General Issues 267
Differences in Properties, Methods, and Events 267
Technology Differences 269
Issues Involving Forms 274
Event Firing Differences 274
The Default Form: DefInstance 277
Application Lifetime and Forms 278
MDI Forms 282
Conclusion 283
13 Upgrading ActiveX Controls and Components 285
ActiveX Controls Are Still Supported—Yes! 285
ActiveX Upgrade Strategy 286
Limitations of ActiveX Control Hosting 286
ActiveX .NET Controls: Best of Both Worlds 289
ActiveX Interop Ax Wrapper: The Windows Forms Wrapper 289
Property and Parameter Type Mappings 290
Standard Component Wrappers and ActiveX Control Subobjects 293
Common Exceptions That Require Type Conversions 295
Name Collisions 297
Event Name Collisions 297
Using ActiveX Components from .NET 298
When ByRef Bites 298
When a Collection Is Not a Collection 299
Nonzero-Bound Arrays 301
Alias Types Are Not Supported 301
Module Methods Are Not Supported 302
Conclusion 303
14 Resolving Data Access Issues 305
Data Access in Visual Basic 306
Code 306
Data Binding 307
ADO Data Environment 307
Components That Don’t Upgrade 308
ADO.NET Is the Future 309
General Issues with Data Access Code 309
DAO and RDO Module Methods 309
ADO Version 2.7 311
Errors in Events 311
RDO Connection 313
Null, vbNullString, and vbNullChar 314
ADO Data Environment 315
Calling Dispose 315
Initialize Event 316
Cursor Location with Microsoft Access Databases 316
ADO Data Binding 316
Control Arrays of ADO Data Controls 318
Setting Data Binding Properties at Run Time 318
Conclusion 321
15 Problems That Require Redesign 323
Replacing the OLE Container Control 323
Replacing Painting Functions 328
Rewriting Clipboard Code 331
Using the Controls Collection 333
Using the Forms Collection 335
Upgrading PrintForm Code 337
Replacing Property Pages 340
Eliminating ObjPtr, VarPtr, and StrPtr 343
Conclusion 345
16 Upgrading COM+ Components 347
COM+ Application Types 347
Using COM+ in Visual Basic .NET 348
COM+ Requirements in Visual Basic .NET 350
Inheriting from the ServicedComponent Class 351
Working with Attributes 352
Creating a Strong Name for Your Assembly 356
Registering COM+ Applications 358
Upgrading COM+ Components 360
Making .NET and COM Components Work Together 364
Conclusion 364
17 Upgrading VB Application Wizard Projects 365
App.Revision 367
frmAbout Form 369
frmLogin Form 370
frmMain Form 370
API Declare Statements 370
mnuHelpAbout_Click Event Procedure 371
App.HelpFile 371
ActiveMdiChild in MDI Projects 372
Forms Collection in frmMain_Closed 374
Clipboard in MDI Projects 375
frmSplash Form 376
frmBrowser Form 378
Data Forms 378
Module1 Module 379
LoadResStrings Method 379
Conclusion 381
PART IV TECHNIQUES FOR ADDING VALUE
18 Adding Value to Your Applications 385
Overview of the Sample Application 386
New File Functions 387
Reading the Contents of a Directory 387
Finding All the Forms in a DLL 388
Loading Forms Dynamically 389
Reading and Writing to Files 389
Using Dynamic Properties 390
New Windows Capabilities 392
Accessing the Registry 392
Control Anchoring 394
Graphics Features 394
Windows XP–Style Controls 398
XCopy Deployment 400
Conclusion 401
19 Replacing ActiveX Controls with Windows Forms Controls 403
Benefits of Upgrading Controls 404
100 Percent .NET Compatibility 404
Improved Versioning 404
Simpler Deployment 405
Process of Replacing Controls 405
Manually Upgrading a Control 406
Mappings for Visual Basic 6 ActiveX Controls 412
ActiveX Controls vs. Windows Forms Controls 413
Conclusion 416
20 Moving from ADO to ADO.NET 417
ADO.NET for the ADO Programmer 417
Overview of ADO.NET 418
DataSets 419
Integrating Your ADO Code into a Visual Basic .NET Application 421
Binding Your ADO Recordset to .NET Controls 422
Using ADO with XML Web Services 423
Mapping ADO Objects to ADO.NET 425
Connection and Command Objects 425
Recordsets 427
Using DataViews 429
Data Binding 430
Binding to Windows Forms Controls 430
A Note About Performance 432
Conclusion 434
21 Upgrading Distributed Applications 435
Important Concepts for Distributed Applications 436
Loosely Coupled vs. Tightly Coupled Applications 436
Overhead in Method Invocation 437
Componentization and Logical Organization 439
Distributed Technologies in .NET 440
XML Web Services 440
Creating a Simple XML Web Service 441
Supporting Web Services in Your Existing Applications 446
Remoting 452
A Simple Remoting Example 453
Architecture for Remoting 456
Distributed COM+ Applications 461
COM+ and Remoting 461
Using SOAP Services 461
COM+ Application Proxies in .NET 463
Conclusion 464
PART V APPENDIXES
APPENDIX A Object Mapping Reference 467
APPENDIX B Function Mapping Reference 515
INDEX