alt
Advertisement

Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow VB.NET 2005 arrow ActiveX Controls and Legacy Code
Site Search
Sponsored Links



ActiveX Controls and Legacy Code
Article Index
ActiveX Controls and Legacy Code
Page 2

.

.

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.

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:


Trackback(0)
Comments (0)add comment

Write comment

busy

 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape