Solved

How to call ActiveX control inside DLL

Posted on 2002-06-14
4
435 Views
Last Modified: 2007-12-19
I am new for VC++ and currently writing a DLL which should be able to invoke function of the ActiveX control.

I tried to create a new win32 DLL project from VC and added a reference to the ActiveX control. However, I failed to add the reference to the activeX control and got the following message

"The Components and Controls Gallery can only be used to add AcitveX control to projects that a supported by ClassWizard. See help topic 'Adding an ActiveX control to a project' for more information"

Then I found the ClassWizard function was disabled in the menu (ClassWizard function is enabled in the Win32 application project).

Do I miss anything?
How can I invoke function of ActiveX control inside a DLL?

Thanks for any comments or adivse
0
Comment
Question by:nixonc
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 200 total points
ID: 7077707
Normally ActivX controls are window controls.
What type of dll you are using ? I mean Win32 dll? With or Without MFC Support ? Is this dll handles any windows ?

You have to include ActiveX wrapper class to use the control.
Or you can create the control dynamically.

Find "Write ActiveX Controls Using Custom Interfaces Provided by ATL 3.0, Part III" or "HOWTO: Dynamically Add ActiveX Controls to ATL Composite Control" in MSDN.

But my suggession is create an ATL control instead of ActiveX. That is the most suited in your application. Becoz, you are only want to do a function with that control.

GOOD LUCK
0
 
LVL 3

Expert Comment

by:Blacklord_76
ID: 7078282
First yuo need to import the information about ActiveX to your application. You need to type something like this :

#import "msgArchiver.dll" named_guids raw_interfaces_only \no_namespace rename_namespace ("Arch")

after that if you rebuild the project, you can see in intermediate directory (Debug, for example) two files
with extension .tlh and .tli
after that you can use the COM objects.
You NEED to read carefully the reference about #import directive. Content of generated files is COM class wrappers, GUID reference and so on , imported from specified DLL(for example) and depends on #import . You can use that like usual C++ classes. Don't forget to COM Init/DeInit.

HRESULT hr  = S_OK;
hr  = CoInitialize(0);
hr = CoCreateInstance(CLSID_MsgHandler,
NULL,CLSCTX_INPROC_SERVER |CLSCTX_LOCAL_SERVER,
                    IID_IMsgHandler,(void **)
&spHandler);
CoUnitialize();


This is only general case. But may be it enought for you now :)

0
 
LVL 3

Expert Comment

by:Blacklord_76
ID: 7078605
First yuo need to import the information about ActiveX to your application. You need to type something like this :

#import "msgArchiver.dll" named_guids raw_interfaces_only \no_namespace rename_namespace ("Arch")

after that if you rebuild the project, you can see in intermediate directory (Debug, for example) two files
with extension .tlh and .tli
after that you can use the COM objects.
You NEED to read carefully the reference about #import directive. Content of generated files is COM class wrappers, GUID reference and so on , imported from specified DLL(for example) and depends on #import . You can use that like usual C++ classes. Don't forget to COM Init/DeInit.

HRESULT hr  = S_OK;
hr  = CoInitialize(0);
hr = CoCreateInstance(CLSID_MsgHandler,
NULL,CLSCTX_INPROC_SERVER |CLSCTX_LOCAL_SERVER,
                    IID_IMsgHandler,(void **)
&spHandler);
CoUnitialize();


This is only general case. But may be it enought for you now :)

0
 

Author Comment

by:nixonc
ID: 7080145
Thank you very much. I think I have solved the problem. I should create a project of MFC AppWizard (dll) instead of win32 dll.

Anyway, I think roshmon's comment help me a lot.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question