ActiveX and interfaces
Hello,
I created an ActiveX object in VC++ 6.0 with MFC (not ATL), and tried it. It seems to compile and run perfectl, performing exactly what I programmed.
My concern is that I have been looking in the code generated by VC++, and didn't find any implementation of the so called AddRef(), Release() and QueryInterface() methods.
Do I need to implement those three methods or not ? And if I need to do it, what code should I use ? And how is it possible that my ActiveX is working perfectly ?
Sorry, but I am something new at ActiveX developpement.
Thank you for any hint.
[621 byte] By [
alcor] at [2007-11-19 9:13:30]

# 1 Re: ActiveX and interfaces
If you are using smart pointers like CComQIPtr, CComPtr, and the likes, you don't have to worry about doing AddRef, and Release.
# 2 Re: ActiveX and interfaces
Thank you for the answer.
No, I don't use smart pointers ( at least, I don't think so).
I use the app generated by Visual C++ when creating an ActiveX projet, and then add my own COM method via the Class Wizard.
My ActiveX is made to download files via some http urls, so it mainly call these urls, get the data from them, create a new file on the hard disk and save the data retrieved from the url.
The code is MFC (I mean I use CFile, CString and so on).
So my question is still the same : do I need to implement these methods to my own interface ? And if the answer is yes, how can you explain that the ActiveX works very well without this code ?
Thanks.
alcor at 2007-11-11 0:22:15 >

# 3 Re: ActiveX and interfaces
You must have implemented these methods accidentally ;-) Did you use a wizard to develop your control?
These methods certainly need implementing, as do the methods of IDispatch.
Markus.
# 4 Re: ActiveX and interfaces
Indeed I used a Wizard for creating my ActiveX, as I said it's VC++ 6.0, and then Class Wizard for adding my own methods.
You can make the test yourself with VC++ 6.0 : just create a new project , and choose MFC ActiveX controlwizard.
Then click "finish" and you've got the ActiveX project ready to compile and to run.
But even with "Find in files" tool (from the Edit menu) you'll never find "QueryInterface" (and BTW, you'll never find IUnknown nor IDispatch either).
alcor at 2007-11-11 0:24:11 >

# 5 Re: ActiveX and interfaces
More information about the ActiveX control wizard can be found here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_prepare_your_mfc_activex_control_program_for_use.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_add_code_to_the_mfc_activex_control_starter_files.asp
alcor at 2007-11-11 0:25:12 >

# 6 Re: ActiveX and interfaces
The implementations of IDispatch and IUnknown are hidden somewhere deep in the bowels of MFC. You'd have to look through the MFC source to find them.
If you really want to learn how activeX works, you should probably try to create a small activeX object without using MFC or ATL. The idea behind class libraries like MFC and ATL is to hide the difficult stuff! :-)
Markus
# 7 Re: ActiveX and interfaces
Thank you.
All what I want to know for the moment, is if I have to implement the methods or not.
According to your answer, and to the fact that my ActiveX works perfectly, I understand I do not need to implement them.
As my mom use to say, "never fix something which has not been broken !" ;-)
alcor at 2007-11-11 0:27:18 >
