Exforsys

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor

Ads


Home arrow Technical Training arrow VB.NET 2005

ActiveX Controls and Legacy Code Page - 2

Page 2 of 2
Author : Exforsys Inc.     Published on: 30th Jul 2005    |   Last Updated on: 24th Dec 2007

ActiveX Controls and Legacy Code

Ads

Using ActiveX Controls on Windows Forms

An ActiveX control is a COM component that supports standard interfaces relating to persistence, connection points, and hosting. Hosting in a control container, exchange of messages and handling of events are achieved by a protocol defined by the standard interfaces mentioned above. ActiveX Controls have properties, Methods, Events and Type Library details of which are given below: ..

Term Description
Properties  Controls have member variables to represent internal state and are implemented as Get and Set accessor functions. A Get function is generated for each accessor method with a propget tag in the .idl file. A Set function is generated for each accessor method with either a propput or propputref IDL tag. Use wrapper classes or the OLE/COM Object Viewer to determine how accessor functions are defined.
Methods  A control's behavior is defined by its public methods. Wrapper classes give you access to a control's methods
Events   A control can generate an event to notify the host that something happened.
Type Library  A type library tells a control container what properties, methods, and events are supported by a control.

Windows Forms Designer is tailored to host Windows Forms Controls. However, ActiveX controls can be added on Windows Forms. But there will be some limitations imposed on the performance such ActiveX controls that are added. The procedure to add the controls to the Form is to be preceded by adding the ActiveX components to the ToolBox. This is done as follows:

  1. Right click on the ToolBox and click on the Choose ToolBox Item on the context menu
  2. Click on the tab COM components which will show the COM components registered.
  3. Click on the CheckBox that appears next to the item that you want to add and click OK. This will add the ActiveX component to the ToolBox.
  4. Now you need to add the components to the Form. This is achieved by double clicking on the control in the ToolBox. Visual studio adds all references to the control in your project.

There are certain considerations when hosting an ActiveX Control on a Windows Form. We shall briefly see the issues involved.

Security: The CLR has been provided with code access security. Because of this, windows Forms can run in a fully trusted environment and also in the semi-trusted environment with most of the functionality intact. Windows forms controls can also be hosted in a browser with no complications. However this is not the case with ActiveX controls, which require unmanaged code permission.

Resource cost: ActiveX controls added to a Windows Form are deployed with that Windows Form in their entirety. This adds significantly to the size of the files created. Added to this, the use of ActiveX controls also need use of registry entry.

Using Platform Invoke

Platform invoke is a service that enables managed code to call unmanaged functions implemented in DLLs. Platform invoke depends on metadata to locate exported functions and marshal their arguments at run time.

The following sequence of actions are performed when platform invoke calls an unmanaged code.

  1. Locate the DLL containing the function
  2. Loads the DLL into memory
  3. Locates the address of the function in memory and pushes its arguments onto the stack, marshaling data as required.
  4. Transfers control to the unmanaged function

Platform invoke throws exceptions generated by the unmanaged function to the managed caller. Now let us proceed to learn how we can consume unmanaged DLL functions:

In order to consume the unmanaged DLL functions, the user may have to carry out several tasks. The following list is useful in making your exposure to DLL functions.

  1. Identify the functions in DLLs
  2. Specify the name of the function and the name of the DLL that contains it.
  3. Create a class to hold DLL functions:
  4. Use an existing class,
  5. Create an individual class for each unmanaged function,
  6. Or create one class that contains a set of related unmanaged functions.

In this lesson we have examined in detail the process of handling legacy code and the various factors that have to be taken into consideration in the process. In the next lesson we shall look at the process of testing and debugging a Windows application.

Option Description
/delaysign Specifies to Aximp.exe to sign the resulting control using delayed signing.
/help Displays command syntax and options for the tool
/keycontainer:containerName Signs the resulting control with a strong name using the public/private key pair found in the key container specified by ContainerName
/keyfile:filename Signs the resulting control with a strong name using the publisher's official public/private key pair found in filename.
/nologo Suppresses the Microsoft startup banner display.
/out:filename Specifies the name of the assembly to create.
/publickey:filename Signs the resulting control with a strong name using the public key found in the file specified by filename.
/silent Suppresses the display of success messages.
/source Generates C# source code for the Windows Forms wrapper.
/verbose Specifies verbose mode; displays additional progress information.
/? Displays command syntax and options for the tool.

Ads

Aximp.exe converts the whole ActiveX control type library and produces a set of assemblies that contain the common language runtime metadata and control implementation for the types defined in the original type library. The out put files are named as under:



 
This tutorial is part of a VB.NET 2005 tutorial series. Read it from the beginning and learn yourself.

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor
 

Comments