Solved

How to call ActiveX control inside DLL

Posted on 2002-06-14
4
417 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now