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

Windows Kernel

Development Platform:

Visual C++

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #ifdef POSTSPLIT
  4. // This function checks if a given URL already has a subscription.
  5. // Returns TRUE: if it aleady has a subscription 
  6. //         FALSE: Otherwise.
  7. //
  8. BOOL CheckForExistingSubscription(LPCTSTR lpcszURL)
  9. {
  10.     HRESULT hr;
  11.     ISubscriptionMgr *psm;
  12.     BOOL    fRet = FALSE;  //Assume failure.
  13.     //Create the subscription Manager.
  14.     hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  15.                           CLSCTX_INPROC_SERVER,
  16.                           IID_ISubscriptionMgr,
  17.                           (void**)&psm);
  18.     if (SUCCEEDED(hr))
  19.     {
  20.         BSTR bstrURL = SysAllocStringT(lpcszURL);
  21.         if (bstrURL)
  22.         {
  23.             psm->IsSubscribed(bstrURL, &fRet);
  24.             SysFreeString(bstrURL);
  25.         }
  26.         psm->Release();
  27.     }
  28.     return(fRet);
  29. }
  30. BOOL DeleteFromSubscriptionList(LPCTSTR pszURL)
  31. {
  32.     BOOL fRet = FALSE;
  33.     HRESULT hr;
  34.     ISubscriptionMgr *psm;
  35.     hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  36.                           CLSCTX_INPROC_SERVER,
  37.                           IID_ISubscriptionMgr,
  38.                           (void**)&psm);
  39.     if (SUCCEEDED(hr))
  40.     {
  41.         BSTR bstrURL = SysAllocStringT(pszURL);     // Call TSTR version
  42.         if (bstrURL)
  43.         {
  44.             //  Looks like all code paths going through this has already
  45.             //  put up some UI.
  46.             if (SUCCEEDED(psm->DeleteSubscription(bstrURL, NULL)))
  47.             {
  48.                 fRet = TRUE;
  49.             }
  50.             SysFreeString(bstrURL);
  51.         }
  52.         psm->Release();
  53.     }
  54.     return(fRet);
  55. }
  56. BOOL UpdateSubscription(LPCTSTR pszURL)
  57. {
  58.     BOOL fRet = FALSE;
  59.     HRESULT hr;
  60.     ISubscriptionMgr *psm;
  61.     hr = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  62.                           CLSCTX_INPROC_SERVER,
  63.                           IID_ISubscriptionMgr,
  64.                           (void**)&psm);
  65.     if (SUCCEEDED(hr))
  66.     {
  67.         BSTR bstrURL = SysAllocStringT(pszURL);     // Call TSTR version
  68.         if (bstrURL)
  69.         {
  70.             if (SUCCEEDED(psm->UpdateSubscription(bstrURL)))
  71.             {
  72.                 fRet = TRUE;
  73.             }
  74.             SysFreeString(bstrURL);
  75.         }
  76.         psm->Release();
  77.     }
  78.     return(fRet);
  79. }
  80. //
  81. //
  82. // This function enumerates the URLs of all the desktop components and then
  83. // calls webcheck to see if they are subcribed to and if so asks webcheck to
  84. // deliver those subscriptions right now.
  85. //
  86. //
  87. BOOL UpdateAllDesktopSubscriptions()
  88. {
  89.     IActiveDesktop  *pActiveDesktop;
  90.     ISubscriptionMgr *psm;
  91.     int     iCount; //Count of components.
  92.     HRESULT     hres;
  93.     BOOL        fRet = TRUE;  //Assume success!
  94.     if(FAILED(hres = CActiveDesktop_InternalCreateInstance((LPUNKNOWN *)&pActiveDesktop, IID_IActiveDesktop)))
  95.     {
  96.         TraceMsg(TF_WARNING, "Could not instantiate CActiveDesktop COM object");
  97.         return FALSE;
  98.     }
  99.     pActiveDesktop->GetDesktopItemCount(&iCount, 0);
  100.     if(iCount <= 0)
  101.     {
  102.         TraceMsg(DM_TRACE, "No desktop components to update!");
  103.         return TRUE; //No components to enumerate!
  104.     }
  105.     //Create the subscription Manager.
  106.     hres = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  107.                             CLSCTX_INPROC_SERVER,
  108.                             IID_ISubscriptionMgr,
  109.                             (void**)&psm);
  110.     if(SUCCEEDED(hres))
  111.     {
  112.         int iIndex;
  113.         BSTR bstrURL;
  114.         //Enumerate the desktop components one by one.
  115.         for(iIndex = 0; iIndex < iCount; iIndex++)
  116.         {
  117.             COMPONENT   Comp;   //We are using the public structure here.
  118.             Comp.dwSize = sizeof(COMPONENT);
  119.             if(SUCCEEDED(pActiveDesktop->GetDesktopItem(iIndex, &Comp, 0)) && 
  120.                         Comp.fChecked)  //Is this component enabled?
  121.             {
  122.                 BOOL    fSubscribed;
  123.                 fSubscribed = FALSE;  //Assume that it is NOT subscribed!
  124.                 bstrURL = SysAllocString(Comp.wszSubscribedURL);
  125.                 if(!bstrURL)
  126.                 {
  127.                     fRet = FALSE;
  128.                     break;  //Out of memory!
  129.                 }
  130.                 psm->IsSubscribed(bstrURL, &fSubscribed);
  131.                 if(fSubscribed)
  132.                     psm->UpdateSubscription(bstrURL);
  133.                 SysFreeString(bstrURL);
  134.             }
  135.             else
  136.                 TraceMsg(TF_WARNING, "Component# %d either failed or not enabled!", iIndex);
  137.         }
  138.         psm->Release();
  139.     }
  140.     else
  141.     {
  142.         TraceMsg(TF_WARNING, "Could not create CLSID_SubscriptionMgr");
  143.     }
  144.         
  145.     pActiveDesktop->Release();
  146.     return (fRet);
  147. }
  148. #endif