HOWTO: Determining Whether a User Is Subscribed to a Channel

Last reviewed: January 19, 1998
Article ID: Q175504
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 determine whether a user is already subscribed to a channel, so that a Web page or an application does not redundantly offer users the ability to subscribe to a channel they've already subscribed to.

MORE INFORMATION

This article describes how to check a subscription from C++, Visual Basic, and script.

C++ - using ISubscriptionMgr::IsSubscribed

The code below demonstrates how this can be done using C++, from a console application:

   #include <windows.h>
   #include <tchar.h>
   #include <iostream.h>
   #include <subsmgr.h>
   #include <stdio.h>

   void main()
   {
      ISubscriptionMgr *pSubscriptionMgr;
      CoInitialize(NULL);

      HRESULT hr = CoCreateInstance(CLSID_SubscriptionMgr,
                                    NULL,
                                    CLSCTX_INPROC_SERVER,
                                    IID_ISubscriptionMgr,
                                    (void**)&pSubscriptionMgr);
      if (SUCCEEDED(hr))
      {
         BOOL Bool;
         BSTR bstrURL =
           SysAllocString(L"http://test.microsoft.com/tst.cdf");
         hr = pSubscriptionMgr->IsSubscribed(bstrURL, &Bool);

         pSubscriptionMgr->Release();

         char szBuffer[250];
         TCHAR szURL[200];
         WideCharToMultiByte(CP_ACP, 0, bstrURL, -1, szURL, 200, NULL,
                             NULL);
         if (Bool)
             wsprintf (szBuffer,"YES, you are subscribed to %s\n",szURL);
         else
             wsprintf (szBuffer,"NOPE, you are NOT subscribed to %s\n",
                        szURL);
         cout << szBuffer;
         SysFreeString (bstrURL);
      }

      CoUninitialize();
   }

Visual Basic - Using the ShellUIHelper Object

The code below demonstrates how this can be done in a standard Visual Basic application. To use the ShellUIHelper object, use Project->References to add a reference to "Microsoft Internet Controls."

   Private Sub Form_Load()
       Dim ShlHlpr As ShellUIHelper

       Set ShlHlpr = New ShellUIHelper

       If ShlHlpr.IsSubscribed("http://test.microsoft.com/tst.cdf") Then
           MsgBox "You're Subscribed!"
       Else
           MsgBox "You're not Subscribed!"
       End If
   End Sub

Script - Using window.external.isSubscribed

The code below demonstrates how this can be done, using JavaScript in an .htm page:

   <SCRIPT>
     if (window.external.isSubscribed("http://test.microsoft.com/tst.cdf"))
        alert ("You are subscribed!");
     else
        alert ("You are NOT subscribed!");
   </SCRIPT>

Cross-frame security rules apply to this script call. Script in a document can only check to see if the user is subscribed to sites on the same domain.

REFERENCES

Internet Client SDK documentation

Keywords          : iegeneral kbcode
Technology        : 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.