My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
   
SUBSCRIPTION STATUS
If you are a subscriber to this publication, sign-in to access locked articles. To subscribe or renew go to www.AdvisorStore.com.
Go to Article
Advanced Search 

VISUAL BASIC PROGRAMMING

.NET and VB6 COM Interoperability Basics

Microsoft .NET lets you create applications that leverage your existing investment in VB6 COM components. Get started by learning the basics of this interoperability, including the concepts of marshaling, blitting, and managed and unmanaged code.

By Alok Mehta


Despite the growing popularity of Microsoft Visual Basic .NET (VB.NET), many companies are still running components written in VB6 code. For the moment, these two components (VB6 and .NET) must co-exist. Eventually, more robust .NET objects will replace VB6 components. However, this transition will take time. During this evolution, developers will have to deal with interoperability to make VB6 and .NET code sets talk to each other.
Figure 1: Interoperability basics 1-- Use marshalling in a .NET application.

Figure 2: Interoperability basics 2 -- Using marshalling can cause a performance hit.

Specifically, the .NET runtime's interoperability services let you write Visual Basic .NET applications that use existing VB6 ActiveX DLLs or other Component Object Model (COM) DLLs. They also let you write VB6 applications that use DLLs created with VB.NET. You can create .NET applications that leverage your existing investment in COM components, and you can use a VB6 ActiveX DLL in VB.NET and still access its functionality from VB6 applications.

Interoperability basics: marshaling, blit, managed, and unmanaged

When code from one platform calls a method on an object running on the other platform, the method call requires marshaling. In marshaling, the .NET interoperability services package up the method call, transfer it to the other platform, invoke the method, package the results, and transfer them back to the original platform. Figures 1 and 2 show this process. Marshalling causes a performance hit as the process moves the parameters from one platform to the other.

This performance hit varies depending on the data types of the parameters. Performance is best when you're moving simple numeric data, such as a 32-bit integer. This is called a blittable data type. The term "blittable" refers to the fact that you can simply copy, or blit, data from .NET memory to COM memory (or vice versa). Examples of blittable data types are Byte, Integer, and Long. However, data types such as Boolean are non-blittable and require conversion from one format to another when they're marshaled from one platform to another. The .NET and COM platforms represent and store blittable data types in memory the same way. As a result, interoperability between them is almost as quick as regular method calls.

Another interesting concept is managed and unmanaged code. Code executing under the control of the .NET runtime libraries is called managed code. Conversely, code that runs outside the runtime is called unmanaged code. COM components, ActiveX interfaces, and Win32 API functions are examples of unmanaged code. Under the managed code scenario, .NET provides complete control of components' behavior. This control includes features such as memory addressing, exception handling, and error processing. This is possible because of .NET's Common Language Runtime infrastructure, which isn't present in COM or unmanaged components.

This tip is an excerpt from Alok's article "Explore .NET and VB6 COM Interoperability." In the full article, he shows you how VB6 and VB.NET interoperate. He provides two examples: The first describes how to call VB6 from .NET, and the second shows how to call .NET from VB6. ACCESS ADVISOR magazine subscribers can read the full article online at http://Advisor.com/doc/14478.


Printer-friendly
page layout

.NET and VB6 COM Interoperability Basics

1 reader comment:

What do YOU think about this topic? Share your advice and thoughts using this form.

Your Name

REQUIRED : PUBLIC

Your E-Mail

REQUIRED : PRIVATE

Job, Company

OPTIONAL : PUBLIC

City, State, Country

OPTIONAL : PUBLIC

Your Web Site

OPTIONAL : PUBLIC

Your Comment

Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

Alok Mehta is senior vice president and chief technology officer of AFS Technologies in Weston, Massachusetts. He recently completed his Ph.D. in computer science from Worcester Polytechnic Institute.

ARTICLE INFO

Web Edition: 2005 Week 03, Doc #15953

FREE ACCESS FREE ACCESS

Keyword Tags: ActiveX, Application Development, COM - Component Object Model, Development, Microsoft, Microsoft Visual Basic, Microsoft Visual Basic .NET, Microsoft .NET, Microsoft .NET Framework, Software Development, Visual Basic (VB)

Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
Portions copyright ©1983-2010 Advisor Media, LLC. All Rights Reserved.
Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, LLC in the United States and/or other countries.
Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
Hosted by Prominic.NET Website powered by
LOTUS SOFTWARE
oa MEHTA15-01 posted 2005-1-17 mod 02/08/2010 03:12:53 AM ztdbms/ztdbms
domino-144.advisor.com my.advisor.com 02/08/2010 06:13:05 PM