Solved

How to call ActiveX control inside DLL

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

863 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

26 Experts available now in Live!

Get 1:1 Help Now