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

 
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 
Hi,
I'm writing Window apllication, using Winforms. I want send a mail programatically using default mail client (Outlook), The mailing facility shoud have attachement facility too.
Please let me know if any one has implemented this.
 
-Dharanendra

 
-Dharanendra
AnswerRe: Send a mail using default mail Client (Outlook).memberWizard1220 Feb '07 - 6:45 
Why dont you check my other article - http://www.codeproject.com/csharp/sendtaskspgmticly.asp[^]
 
________________________
Mercy.GP.,
Consultant,
 
Satyam Computer Services Limited,
India.

GeneralActive X problem.memberabhi_638320 Jun '06 - 22:48 
I have this active x object. say datamanager. and i have imported it.
now to use in c#, i drag drop it in the form. and then use it.
i want to use this active x, w/o using the form.
i.e in my class i want to create it using new and use it like i've been using in the form.
i tried using the code(modified offcourse), which is generated by form designer, in my class.
But exception occurs when i call for any function, lets say, openconnection() for this datamanager,
stating the object is in invalid state.
Please help.
 
Abhimanyu
GeneralI don't have MAPI!memberjloiscan11 Apr '05 - 5:19 
I am using a Microsoft Windows 2000. I believe I don't have the MAPI in my system because I couldn't find the component library C:\\winnt\system32\msmapi32.ocx. I am new to C#. I am wondering if anyone could help me test this tutorial, i.e. I would need the MAPI Component library. Thank you.
 
By the way, is there a difference between the two ways to import ActiveX controls: generating the assembly first then add it to the project vs. adding the component library directly to the toolbox? Thanks again.
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 
You aren't really demonstrating anything new here. You're showing how to use an existing tool in a straightforward manner, and then generate some code to do something fairly basic.
 
So, why did you write this article? Did it help you solve a bigger problem? This might be of interest to the reader and make your article stronger.
 
May I also suggest:
 
http://www.codeproject.com/useritems/WhatIsAGoodArticle.asp[^]
 
Marc
 
Help! I'm an AI running around in someone's f*cked up universe simulator.

sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus

GeneralRe: A couple suggestionsmemberWizard1215 Dec '02 - 17:41 
Just read the title. Its all about importing ActiveX controls and not to explain what one should do after importing the control. I intentionally put it in a straight forward manner thats because, I had beginners in my mind and as a beginner, I was searching for something like this. Think I've done justice to my thought.
 

 
________________________
Mercy.GP.,
Jr. Software Development Engineer,
 
Dell International Services,
Global Strategic Software Center,
India.
GeneralRe: A couple suggestionsmember.S.Rod.16 Dec '02 - 1:08 
Wizard12 wrote:
I was searching for something like this
 
...And you forgot to open MSDN, so you wrote that article thinking it was needed.
 

 
Wizard12 wrote:
Its all about importing ActiveX controls
 
In your article, I suggest you answer these straight forward questions :
- Why are there 2 files instead of one after a aximp.exe execution ?
- How those 2 files relate ot each other, at compile-time, at run-time ?
- How do I subscribe to an event source with such a wrapper ? (UCOMIConnectionPoint, ...)
- Relation with the .NET System.Windows.AxHost class ?

GeneralRe: A couple suggestionssussAnonymous8 Dec '03 - 11:32 
I didn't forget to check MSDN (online help I assume not the web site). The on-line help didn't install on my computer.
 
Also often times it's easier to find this sort of information on the Web with that little twist that actually make it work in the real world.
 
Thanks Wizard12 for your efforts in writing this stuff up!
 
Also I found that an example in a book that I have using tlbimp used the /out: option. When using the AxImp leave the /out: off as it doesn't create the dlls as needed for this activity.
GeneralRe: A couple suggestionsmemberJohn H Long22 Mar '05 - 9:09 
Being new to C# this was just the right answer to my problem.
Quick, simple, direct.
 
It's a shame others want to hide answers in complex solutions just to make themselves feel important.
 
Keep up the great work for us beginers.
 

 
Thanks,
John Long
Sandy, Utah USA

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

Permalink | Advertise | Privacy | Mobile
Web04 | 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