Professional Visual Basic Interoperability - COM and VB6 to .NET / Edition 1

Professional Visual Basic Interoperability - COM and VB6 to .NET / Edition 1

by HOLLIS, Rockford Lhotka, Wrox Author Team
     
 

ISBN-10: 1861005652

ISBN-13: 9781861005656

Pub. Date: 02/01/2002

Publisher: Apress

Microsoft .NET marks a huge advance in software development. However, organizations have invested heavily in their existing software infrastructure. Consequently, a lengthy transition period will be necessary in which the new .NET platform must interoperate with old systems. There are major areas of incompatibility between the COM and .NET technologies that prevent a

Overview

Microsoft .NET marks a huge advance in software development. However, organizations have invested heavily in their existing software infrastructure. Consequently, a lengthy transition period will be necessary in which the new .NET platform must interoperate with old systems. There are major areas of incompatibility between the COM and .NET technologies that prevent a simple automated strategy from migrating much VB6 code into Visual Basic .NET. This book investigates these incompatibilities and shows you how to work around them. We start by covering COM interoperability in detail, and then broaden the focus to examine a range of issues that must be handled in order for VB6 and COM code to work with .NET.

Product Details

ISBN-13:
9781861005656
Publisher:
Apress
Publication date:
02/01/2002
Edition description:
2002
Pages:
350
Product dimensions:
(w) x (h) x 0.04(d)

Table of Contents

Introduction1
Who is this Book for?1
What's Covered in this Book?1
What Do I Need to Use this Book?2
Conventions3
Customer Support3
Chapter 1The Importance of Interoperability7
Going Forward with Visual Basic .NET8
Two Strategies - Migration and Interoperability8
The Migration Option8
Major Areas of Incompatibility Between VB6 and Visual Basic .NET9
Good Candidates for Migration to Visual Basic .NET12
Bad Candidates for Migration12
Impossible Migration12
Implications for Interoperability13
Design Situations that Need Interoperability13
Web Services13
Smart Clients14
New ASP .NET Front Ends14
Extending Old Components15
Distributed Processing of Data15
Major Areas of Interoperability15
Calling COM Components from .NET16
Calling .NET Components from COM16
Sharing Data Access Between Old Code and New16
Sharing Configuration Information16
Calling Non-COM DLLs with Static Entry Points17
Wrapping Up17
Chapter 2Using COM Components from .NET19
COM Component Creation20
Building a COM Component20
Binary Compatibility31
Importing COM Components32
Importing During Design32
Importing Dynamically48
Using COM Components49
Early Binding49
Late Binding54
Object Lifetimes58
Multiple Interfaces61
Inheritance64
Inspecting a COM Component from .NET66
Summary75
Chapter 3Using .NET Assemblies from COM77
.NET Assembly Creation78
Building a .NET Assembly78
Setting up for Interop89
Using the [left angle bracket]ComClass()[right angle bracket] Attribute90
Exposing the Class Manually92
Registering .NET Assemblies with COM100
Using Visual Studio .NET101
Using Command-Line Utilities103
Using .NET Objects from COM and Windows107
Early Binding108
Late Binding113
Dealing with Locked Files115
Object Lifetimes115
Multiple and Default Interfaces117
Inspecting a .NET Assembly from COM121
Summary125
Chapter 4Calling COM Components in MTS and COM+ from .NET127
Using COM+ Components128
Creating a COM+ Component129
Calling COM+ Components from Visual Basic .NET142
Queued Components150
Transferring Data160
Using ADO Recordset Objects161
Using Variant Arrays165
Using XML Documents168
Calling .NET Components in COM+ from VB6174
Creating a COM+ Component in .NET175
Making the Class Available to COM Clients182
Summary184
Chapter 5Visual Basic .NET and COM in COM+187
COM+ and VB6188
COM+ and Visual Basic .NET197
Calling VB6 Components from Visual Basic .NET in COM+206
Calling Visual Basic .NET Components from VB6 in COM+209
Summary212
Chapter 6Custom Marshaling215
The Four Different Methods of Marshaling216
Type I Marshaling: Using Tlbimp.exe216
Type II Marshaling (Simple Data Type Marshaling): Adding Attributes to the Interface to Use a Standard Type218
Type III Marshaling: Marshaling into a Custom Data Structure to be Passed Between COM and .NET219
Type IV Marshaling: Implementing the ICustomMarshaler Interface220
Performance Issues222
Type II Marshaling222
IIdasm222
IIasm223
Using IIdasm or IIasm with Type II Marshaling224
Type III Marshaling234
A Type III Example235
Type IV Marshaling247
How it Works247
Managed Code to Unmanaged Code259
Summary260
Chapter 7Threading Issues263
Threading Basics264
Threading Complexity265
Using Single versus Multi-Threading266
Threading in VB6267
Threading in Visual Basic .NET269
Threading Interop269
Calling COM from .NET270
Calling .NET from COM283
Summary283
Chapter 8DCOM, Remoting, and Web Services287
XML Web Services287
.NET Remoting288
DCOM289
XML Web Services and Interop290
Calling COM from .NET290
Calling .NET from COM297
.NET Remoting and Interop302
Calling COM from .NET303
Calling .NET from COM312
Summary316
Chapter 9Sharing Configuration Information319
Private INI Files320
The Structure of an INI File320
Accessing INI Files in VB6321
Accessing INI Files in Visual Basic .NET324
Using the Windows Registry to Store Configuration Settings326
XML-Based Configuration Files328
Accessing XML Configuration Info with the .NET Framework Classes329
Accessing Settings Using System.XML in Visual Basic .NET330
Accessing Settings Using MSXML in VB6332
Concurrency Problems335
Summary335
Chapter 10Flat File Access in .NET337
Random Access to Flat Files338
Random Access in VB6338
Random Access in Visual Basic .NET341
Binary Access to Flat Files345
Binary Access in VB6345
Binary Access in Visual Basic .NET348
Sequential File Access350
Sequential Access in VB6350
Sequential Access in Visual Basic .NET351
Streams as an Alternative in Visual Basic .NET352
Sequential Access with Streaming Techniques353
Binary Access with Streaming Techniques354
Summary355
Chapter 11Using ADO in .NET357
Comparison Between ADO and ADO.NET357
ADO Advantages and Disadvantages358
When is ADO Still Needed in .NET?359
Using ADO in .NET361
ADO Code in Visual Basic .NET362
Data Binding Limitations362
Problems in Setting Some ADO Properties to Strings363
Converting an ADO Recordset into an ADO.NET DataSet364
DAO and RDO Implications366
Summary367
Chapter 12Calling API or Static DLL Functions from .NET369
Reduced Need for Using DLLs with Static Entry Points in .NET370
Reduced Need for Access to Windows API370
Retirement of Older Code373
Platform Invocation Services373
Declaring the API373
Calling the API Function374
Aliasing a Function375
Passing Structures as Parameters375
Data Marshaling Issues378
Getting More Control380
Control Over Data Marshaling380
Using DLLImport Instead of Declare380
Performance Considerations381
Summary382
Chapter 13Interoperability of ActiveX Controls in .NET385
When to Use ActiveX Controls in .NET386
The Differences Between Windows Forms Controls and ActiveX Controls387
Comparison of Properties387
Hosting an ActiveX Control in .NET387
Example--Windows Media Player Control388
Notes on the Example390
Custom Property Moved from Properties List390
Creating a Wrapper with Aximp.exe390
Importing VB6 UserControls391
Controls that Cannot be Imported391
Security391
.NET Windows Forms Controls in VB6392
Summary392
Chapter 14How Do I Prepare VB6 Code for Migration?395
Stop Using Default Properties and Methods396
Avoid Non-Zero Lower Bounds for Arrays396
Make All Parameters Explicitly ByRef or ByVal397
Place Default Values on All Optional Parameters397
Declare All Variables on a Separate Line398
Be Careful Where You Declare Variables398
Avoid Fixed Length Strings in UDTs399
Get Rid of Obsolete Keywords400
Remove Implicit Object Instantiation400
Stop Implicit Loading of Forms401
Switch Data Binding to ADO402
Use Intrinsic Constants Whenever Possible402
Stop Writing DHTML Pages and WebClasses403
Wrap Your API Calls403
Get Your Logic Out of the UI and Into Components and Classes404
Avoid Late Binding404
Summary404

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >