Click here to Skip to main content
Click here to Skip to main content

Importing ActiveX Controls

By , 14 Dec 2002
 

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 = "<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

About the Author

Wizard12
Web Developer
India India
Member
Have a Master of Computer Applications degree from Anna University, Chennai, India. Working as a Technology Specialist for Cognizant, Bangalore, India.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionSend a mail using default mail Client (Outlook).memberMember #205057820 Feb '07 - 0:38 
AnswerRe: Send a mail using default mail Client (Outlook).memberWizard1220 Feb '07 - 6:45 
GeneralActive X problem.memberabhi_638320 Jun '06 - 22:48 
GeneralI don't have MAPI!memberjloiscan11 Apr '05 - 5:19 
GeneralError using the app on a non development computermemberwriteme15 Mar '04 - 16:40 
The code described in this article works when development tools are installed on the computer. On a non development computer it does not work. Tried copying the MSMAPI32.OCX and dependent files using a CAB. The error message is "The control cannot be created because it is not licensed properly". Can you help?
 
Thanks
 
writeme
GeneralA couple suggestionsmemberMarc Clifton15 Dec '02 - 13:54 
GeneralRe: A couple suggestionsmemberWizard1215 Dec '02 - 17:41 
GeneralRe: A couple suggestionsmember.S.Rod.16 Dec '02 - 1:08 
GeneralRe: A couple suggestionssussAnonymous8 Dec '03 - 11:32 
GeneralRe: A couple suggestionsmemberJohn H Long22 Mar '05 - 9:09 
GeneralRe: A couple suggestionsmemberdanilobq4 Jul '06 - 4:09 
GeneralRe: A couple suggestionsprotectorMarc Clifton4 Jul '06 - 4:56 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 15 Dec 2002
Article Copyright 2002 by Wizard12
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid