Tutorials
VB.NET 2005
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:
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.
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.
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.
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:
First Page: ActiveX Controls and Legacy Code