chandir.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //
  2. // test code for chanmgr
  3. //
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <ole2.h>
  9. #include <chanmgr.h>
  10. //
  11. // Macros
  12. //
  13. #define ASSERT(x)   //if(!(x)) printf("ASSERT:line %d: %s", __line__, ##x);
  14. int _cdecl main()
  15. {
  16.     HRESULT hr;
  17.     hr = CoInitialize(NULL);
  18.     if (SUCCEEDED(hr))
  19.     {
  20.         IChannelMgr* pIChannelMgr;
  21.         hr = CoCreateInstance(CLSID_ChannelMgr, NULL,  CLSCTX_INPROC_SERVER, 
  22.                               IID_IChannelMgr, (void**)&pIChannelMgr);
  23.         if (SUCCEEDED(hr))
  24.         {
  25.             ASSERT(pIChannelMgr);
  26.             IEnumChannels* pIEnumChannels;
  27.             
  28.             hr = pIChannelMgr->EnumChannels(CHANENUM_ALL, NULL, &pIEnumChannels);
  29.             if (SUCCEEDED(hr))
  30.             {
  31.                 ASSERT(pIEnumChannels);
  32.                 CHANNELENUMINFO ci;
  33.                 while (S_OK == pIEnumChannels->Next(1, &ci, NULL))
  34.                 {
  35.                     printf("Channel      : %Sn"
  36.                            "Url          : %Sn"
  37.                            "Path         : %Sn"
  38.                            "Subscription : %snn",
  39.                            ci.pszTitle, ci.pszURL, ci.pszPath,
  40.                            ci.stSubscriptionState == SUBSTATE_NOTSUBSCRIBED ?
  41.                                "Not Subscribed" :
  42.                            (ci.stSubscriptionState == SUBSTATE_FULLSUBSCRIPTION ?
  43.                                "Full Subscription" :
  44.                                "Partial Subscription")
  45.                            );
  46.                     CoTaskMemFree(ci.pszTitle);
  47.                     CoTaskMemFree(ci.pszURL);
  48.                     CoTaskMemFree(ci.pszPath);
  49.                 }
  50.                 pIEnumChannels->Release();
  51.             }
  52.        
  53.             pIChannelMgr->Release();
  54.         }
  55.     }
  56.     CoUninitialize();
  57.     return 0;