?
Solved

How to call ActiveX control inside DLL

Posted on 2002-06-14
4
Medium Priority
?
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 600 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

770 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