Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Importing ActiveX Controls

0.00/5 (No votes)
14 Dec 2002 1  
This article is about importing a particular kind of COM component, a graphical one: the ActiveX control.

Importing ActiveX Controls

There are a lot of articles in net for using standard COM components in .NET applications. This article is about importing a particular kind of COM component, a graphical one: the ActiveX control. I�ve tried to import the MSMAPI ActiveX library. Before importing here is a brief introduction to ActiveX and MAPI.

What is an ActiveX control? An ActiveX control is really just another term for �OLE Object� or, more specifically �COM Object�. In another words, it supports IUnknown interface and is also self-registering. With the help of QueryInterface, a container can manage the lifetime of the control, as well as dynamically discover the full extent of a control�s functionality based on the available interfaces. This allows a control to implement as little functionality as it needs to.

MAPI is the Messaging Application Programming Interface, represents a comprehensive set of specifications that link messaging applications on the one hand and the service providers on the other, forming a messaging architecture. Although Microsoft is the prime supplier of MAPI components, it is by no means necessary to have a single Microsoft component to use MAPI (nor it is necessary to use a Windows or Win32 platform, actually). We can have a MAPI-complaint system with third party message store, address guide, and transport providers on a non-Windows operating system. MAPI is a part of WOSA, the Windows Open Services Architecture, which consists of common set of APIs for distributed computing. For more details, read MSDN.

Now, lets see how to import an ActiveX control. There are two ways to use ActiveX controls under .NET. We have an application called AxImp.exe, shipped with .NET SDK. This application does a similar kind of service for ActiveX controls that TlbImp.exe performs for non-graphical COM components. Basically, what it does is, it generates a wrapper component containing a type library that .NET can understand, and this wrapper component is capable of marshalling calls between the .NET runtime and the underlying COM object (the control). This application can from the command line, simply by passing the path and filename of the control.

This will create the file as <old_file.ocx> to <old_file.dll> and Ax<old_file.dll>. After creating the wrapper component add a reference to it and start using the control.

The other way is to import directly to the Visual Studio. We can add the controls to the toolbox by simply right clicking one of the tabs and selecting Customize Toolbox from the context menu. To do this select the COM Components tab and select or browse for the controls, you want to add. Here we want MAPI messages control and session control.

By doing this, we enable the Visual Studio, to create the wrapper component. After this we can use the wrapper component as proxy library, just like any other .NET component. Here is an example, to use this component to log on to MAPI session and send e-mail.

MAPISession objSession = new MAPISession();
MAPIMessages objMsg = new MAPIMessages();
objSession.SignOn();
objMsg.SessionID = objSession.SessionID;
objMsg.Compose();
objMsg.MsgSubject = "MAPI TEST";
objMsg.MsgNoteText = "The message body";
objMsg.RecipAddress = "mailto:mercy_gp@dell.com">mercy_gp@dell.com";
objMsg.ResolveName();
objMsg.Send(null);
objSession.SignOff();

That�s all.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here