Link to home
Start Free TrialLog in
Avatar of nixonc
nixonc

asked on

How to call ActiveX control inside DLL

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
ASKER CERTIFIED SOLUTION
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Blacklord_76
Blacklord_76

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 :)

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 :)

Avatar of nixonc

ASKER

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.