Click here to Skip to main content
15,881,877 members
Articles / Programming Languages / C#
Article

Importing ActiveX Controls

Rate me:
Please Sign up or sign in to vote.
3.18/5 (10 votes)
14 Dec 20022 min read 114.1K   741   19   12
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.

VB
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 = "<a href="mailto:mercy_gp@dell.com">mercy_gp@dell.com</a>";
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


Written By
Architect
United States United States
Architect / Consultant on Content Management and Cloud Computing... Artist and Author by the weekends...

Comments and Discussions

 
QuestionSend a mail using default mail Client (Outlook). Pin
Member 205057820-Feb-07 0:38
Member 205057820-Feb-07 0:38 
AnswerRe: Send a mail using default mail Client (Outlook). Pin
Mercy Ponnupandy20-Feb-07 6:45
Mercy Ponnupandy20-Feb-07 6:45 
GeneralActive X problem. Pin
abhi_638320-Jun-06 22:48
abhi_638320-Jun-06 22:48 
GeneralI don't have MAPI! Pin
jloiscan11-Apr-05 5:19
jloiscan11-Apr-05 5:19 
GeneralError using the app on a non development computer Pin
writeme15-Mar-04 16:40
writeme15-Mar-04 16:40 
GeneralA couple suggestions Pin
Marc Clifton15-Dec-02 13:54
mvaMarc Clifton15-Dec-02 13:54 
GeneralRe: A couple suggestions Pin
Mercy Ponnupandy15-Dec-02 17:41
Mercy Ponnupandy15-Dec-02 17:41 
GeneralRe: A couple suggestions Pin
Stephane Rodriguez.16-Dec-02 1:08
Stephane Rodriguez.16-Dec-02 1:08 
GeneralRe: A couple suggestions Pin
Anonymous8-Dec-03 11:32
Anonymous8-Dec-03 11:32 
GeneralRe: A couple suggestions Pin
John H Long22-Mar-05 9:09
John H Long22-Mar-05 9:09 
GeneralRe: A couple suggestions Pin
danilobq4-Jul-06 4:09
danilobq4-Jul-06 4:09 
GeneralRe: A couple suggestions Pin
Marc Clifton4-Jul-06 4:56
mvaMarc Clifton4-Jul-06 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.