HOWTO: Enumerate Channels in Internet Explorer 4.0

ID: Q178851


The information in this article applies to:


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)

Additional query words:


Keywords          : kbIE400 kbIE401 kbIE500 InetSDKInfoDev 
Version           : WINDOWS:4.0,4.01
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 17, 1999