HOWTO: Enumerate Channels in Internet Explorer 4.0

Last reviewed: January 19, 1998
Article ID: Q178851
The information in this article applies to:
  • Internet Client SDK, versions 4.0, 4.01
  • Microsoft Internet Explorer (Programming), versions 4.0, 4.01

SUMMARY

With the introduction of Active Channels in Internet Explorer 4.0, it may be desirable to enumerate all the channels installed in a system. This article demonstrates how to do this correctly using the new IChannelMgr and IEnumChannels interfaces documented in the Internet Client SDK.

MORE INFORMATION

The following code enumerates the channels using the two interfaces, IChannelMgr and IEnumChannels, and adds every channel element retrieved into a listbox:

   #define INITGUID
   #include <objbase.h>
   #include <initguid.h>
   #include <chanmgr.h>      // This .h file defines the 2 interfaces

   CListBox *pList;
   HRESULT hr;
   IChannelMgr   *pChannelMgr;
   IEnumChannels *pIEnumChannels;

   pList = (CListBox*)GetDlgItem(IDC_LIST1);
   if (FAILED(hr = CoInitialize(NULL)))
      return FALSE;

   hr = CoCreateInstance(CLSID_ChannelMgr,
                         NULL,
                         CLSCTX_INPROC_SERVER,
                         IID_IChannelMgr,
                         (void**)&pChannelMgr);

   hr = pChannelMgr->EnumChannels(CHANENUM_CHANNELFOLDER |
                                  CHANENUM_TITLE |
                                  CHANENUM_PATH |
                                  CHANENUM_URL,
                                  NULL,
                                  &pIEnumChannels);
   if (SUCCEEDED(hr))
   {
      ASSERT(pIEnumChannels);
      CHANNELENUMINFO ci;

      while (S_OK == pIEnumChannels->Next(1, &ci, NULL))
      {
          // Do something with the path here.
          TCHAR szTitle[200];
          TCHAR szPath[200];
          TCHAR szURL[200];
          TCHAR szBuffer[500];

          WideCharToMultiByte(CP_ACP, 0, ci.pszTitle, -1, szTitle, 200,
                              NULL,
                              NULL);
          WideCharToMultiByte(CP_ACP, 0, ci.pszPath, -1, szPath, 200, NULL,
                              NULL);
          WideCharToMultiByte(CP_ACP, 0, ci.pszURL, -1, szURL, 200, NULL,
                              NULL);
          //TRACE ("%s + %s + %s\r\n", szTitle, szPath, szURL);

          wsprintf (szBuffer,"%s (%s)",szTitle, szURL);
          pList->AddString (szBuffer);

          CoTaskMemFree(ci.pszTitle);
          CoTaskMemFree(ci.pszPath);
          CoTaskMemFree(ci.pszURL);
      }
   }

   pIEnumChannels->Release();
   CoUninitialize();

REFERENCES

"Internet Tools & Technologies\Information Delivery API" section of the Internet Client SDK (http://www.microsoft.com/msdn/sdk/inetsdk/help)

Keywords          : InetSDKInfoDev
Technology        : internet kbinetdev
Version           : WINDOWS:4.0,4.01
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 19, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.