How to Call CoGetClassObjectFromURL() in an MFC App

ID: Q174653


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
  • Microsoft Internet Explorer (Programming) versions 4.0, 4.01


SUMMARY

This Urlobj.exe sample demonstrates how to call the CoGetClassObjectFromURL() function to download, register, and instantiate an object. The sample implements two interfaces necessary to allow the CoGetClassObjectFromURL() function to work properly: IBindStatusCallback and IWindowForBindingUI.


MORE INFORMATION

The following files are available for download from the Microsoft Download Center. Click the file names below to download the files:


Urlobj.exe

For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address

http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

The CoGetClassObjectFromURL() function returns a class factory object for a given CLSID. If the desired object is installed on the system, it is instantiated. Otherwise, the necessary code is downloaded and installed from the specified URL. The sample uses a CFormView to get the value of the CLSID, the URL pointing to the code for the ActiveX object, the major and minor version, and the size of the object for displaying (it assumes that the control will display itself in some manner).

The bulk of the relevant code is found in the OnButton1() handler, which starts the download process, and the OnStopBind() handler, which handles creating the object after it has finished downloading.

The IBindStatusCallback and IWindowForBindingUI interfaces are implemented in the file Download.cpp by using a CCmdTarget derived class and the MFC interface map macros.

After the CoGetClassObjectFromURL() has completed the asynchronous download, the OnStopBind() handler is called to display the control. In this handler the sample demonstrates instantiating the actual object by using the CWnd::CreateControl() function. This is assuming that the object is an OLE control. The handler also contains some code that has been commented out that demonstrates calling IClassFactory::CreateInstance() in the case that the object is not an OLE control.

To maintain simplicity, the sample does not implement much error checking or verification of user input.

Additional query words: softlib

Keywords : kbfile kbVC500 kbVC600 kbWinInet
Version : WINDOWS:4.0,4.01; winnt:5.0,6.0
Platform : WINDOWS winnt
Issue type :


Last Reviewed: December 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.