次の方法で共有


C++ リファレンスの概要

このライブラリは、コンテンツ プロバイダが申込者に通知を送信するための便利な方法を提供します。このライブラリで提供される Component Object Model (COM) オブジェクトを使用すると、通知を (抽象オブジェクトとして) 作成し、それらを Microsoft® .NET Alerts ルーティング エンジンに送信して配信できます。

オブジェクト インターフェイス

INotificationTransport インターフェイス 通知用の高性能な HTTP トランスポート サービスを提供します。
IMsnNotification インターフェイス 通知の抽象化を行います。
INotificationsUtility インターフェイス .NET Alerts ライブラリ用の一般的なユーティリティ機能を提供します。
DNotificationTransportEvents インターフェイス INotificationTransport インターフェイスのイベントを提供するディスパッチ インターフェイスです。

お使いになる前に

IDL ファイルを処理し、クライアント ライブラリのヘッダー ファイルと IID 定義ファイルを作成するには

  1. コマンド プロンプトを開き、Microsoft MIDL コンパイラを実行します。入力ファイルとして msnotify.idl を指定します。このファイルは、.NET Alerts Software Development Kit (SDK) に付属しています。この IDL ファイルからヘッダー ファイルが生成されるように指定するには、/h スイッチを使用します。この IDL ファイルから IID 定義ファイルが生成されるように指定するには、/iid スイッチを使用します。

    次のコマンドを実行すると、MIDL は msnotify.idl を読み取り、msnotify.h というヘッダー ファイルと msnotify_iid.h という IID ヘッダー ファイルを生成します (画面出力はユーザーの設定によって異なります)。

  2. #include ディレクティブを使用して、msnotify.h と msnotify_iid.h の各ヘッダー ファイルをプロジェクトに含めます。この作業によって、.NET Alerts クライアント ライブラリのオブジェクトを作成および使用できるようになります。

詳細については、「Using the MIDL Compiler 外部リンク」を参照してください。

次の C++ の例では、クライアント ライブラリの基本的な使い方を説明するコンソール アプリケーションを実装します。このコードは、msnotify.h、msnotify_iid.h、および notifysink.cpp を含むディレクトリがプロジェクトのインクルード ディレクトリとして指定されていることを前提としています。

#define UNICODE

#include <iostream>
using namespace std;

// Microsoft .NET Alerts client library files.
#include "msnotify.h"
#include "msnotify_iid.h"

// Implementation file for an OnCompletion handler.
// An OnCompletion handler is necessary only if you
// are sending alerts asynchronously.For more information,
// see DNotificationTransportEvents::OnCompletion Event.
#include "notifysink.cpp"

// Prototypes.
void ShowErrorMessage(HRESULT hr);
void ShutDown(INotificationTransport    *pITransport,
    INotificationsUtility       *pIUtility,
    IMsnNotification        *pIAlert,
    IConnectionPoint        *pIConnectionPoint,
    IConnectionPointContainer   *pIConnectionPointContainer,
    CNotifySink     *pCNotifySink,
    HRESULT         hr);
void InitAsync(INotificationTransport   *pITransport,
    IConnectionPointContainer   *pIConnectionPointContainer,
    IConnectionPoint        *pIConnectionPoint,
    CNotifySink     *pCNotifySink);

void DemoSendNotification(IMsnNotification *pIAlert, INotificationTransport *pITransport);
void DemoDrainNotifications(INotificationTransport *pITransport);
void DemoAddToPID(IMsnNotification *pIAlert);
void DemoGetSerialization(IMsnNotification *pIAlert);
void DemoGetCPA(INotificationsUtility *pIUtility);

// Global variables.
CRITICAL_SECTION g_cs;

int main () {

    // Interface pointers for a transport object, an alert
    // object, and a utility object.
    INotificationTransport      *pITransport    = 0;
    INotificationsUtility       *pIUtility      = 0;
    IMsnNotification        *pIAlert        = 0;

    // You won't need the connection point interfaces or OnCompletion event sink unless
    // you are sending alerts asynchronously.
    IConnectionPointContainer   *pIcpc      = 0;
    IConnectionPoint        *pIcp       = 0;

    // CNotifySink is a user-implemented class designed to be the event sink for
    // the INotificationTransport object.The INotificationTransport object
    // will call the Invoke method of CNotifySink.For more information,
    // see DNotificationTransportEvents::OnCompletion Event.
    CNotifySink     *pCNotifySink   = 0;

    // Turn on the COM subsystem.
    HRESULT hr = CoInitialize(0);

    if (FAILED(hr)) {
        wcout  endl  L"There was a problem initializing COM." endl;
        ShowErrorMessage(hr);
        ShutDown(pITransport, pIUtility, pIAlert, pIcp, pIcpc, pCNotifySink, hr);
    }

    // Create the transport interface.
    hr = CoCreateInstance(
        // Class ID for NotificationTransport.Defined in msnotify_iid.h.
        CLSID_NotificationTransport,
        // No aggregation.
        NULL,
        // MSNOTIFY.DLL is an in-process server.
        CLSCTX_INPROC_SERVER,
        // The interface ID for INotificationTransport.Defined in msnotify_iid.h.
        IID_INotificationTransport,
        // The interface pointer, declared above.
        reinterpret_cast<void **>(&pITransport;));

    if (FAILED(hr)) {
        wcout  endl  L"There was a problem creating the transport interface." endl;
        ShowErrorMessage(hr);
        ShutDown(pITransport, pIUtility, pIAlert, pIcp, pIcpc, pCNotifySink, hr);
    }

    // Create the alert interface.
    hr = CoCreateInstance(
        // Class ID for MsnNotification.Defined in msnotify_iid.h.
        CLSID_MsnNotification,
        // No aggregation.
        NULL,
        // MSNOTIFY.DLL is an in-process server.
        CLSCTX_INPROC_SERVER,
        // The interface ID for IMsnNotification.Defined in msnotify_iid.h.
        IID_IMsnNotification,
        // The interface pointer, declared above.
        reinterpret_cast<void **>(&pIAlert;));

    if (FAILED(hr)) {
        wcout  endl  L"There was a problem creating the alert interface." endl;
        ShowErrorMessage(hr);
        ShutDown(pITransport, pIUtility, pIAlert, pIcp, pIcpc, pCNotifySink, hr);
    }

    // Create the interfaces.
    hr = CoCreateInstance(
        // Class ID for NotificationsUtility.Defined in msnotify_iid.h.
        CLSID_NotificationsUtility,
        // No aggregation.
        NULL,
        // MSNOTIFY.DLL is an in-process server.
        CLSCTX_INPROC_SERVER,
        // The interface ID for INotificationsUtility.Defined in msnotify_iid.h.
        IID_INotificationsUtility,
        // The interface pointer, declared above.
        reinterpret_cast<void **>(&pIUtility;));

    if (FAILED(hr)) {
        wcout  endl  L"There was a problem creating the utilty interface." endl;
        ShowErrorMessage(hr);
        ShutDown(pITransport, pIUtility, pIAlert, pIcp, pIcpc, pCNotifySink, hr);
    }

    // The call to InitAsync will set up an OnCompletion event handler
    // for the transport object.You need to do this only if you will
    // be sending alerts asynchronously.
    InitAsync(
        pITransport,
        pIcpc,
        pIcp,
        pCNotifySink);

    ///////////////////////////////////////////////////////////
    //
    // .NET Alerts client library demonstration functions.
    //
    ///////////////////////////////////////////////////////////

    // Call the demonstration methods for NotificationTransport.
    DemoSendNotification(pIAlert, pITransport);
    DemoDrainNotifications(pITransport);

    // Call the demonstration methods for MsnNotification.
    DemoAddToPID(pIAlert);
    DemoGetSerialization(pIAlert);

    // Call the demonstration methods for NotificationsUtility.
    DemoGetCPA(pIUtility);
    DemoGetGMT(pIUtility);
    SimpleDemoMD5Hash(pIUtility);

    ////////////////////////////////////////////////////////////

    wcout  endl  L"The program completed normally." endl;
    ShutDown(pITransport, pIUtility, pIAlert, pIcp, pIcpc, pCNotifySink, S_OK);

    // Should never get here, but just in case...
    return E_FAIL;

} // End main.

void ShowErrorMessage(HRESULT hr) {

    // For FormatMessage()
    void *pvErrorText = 0;
    // To count the number of characters returned by FormatMessage().
    DWORD dwChars = 0;

    // Get the system-defined description for this error.
    dwChars = FormatMessage(
        // Flags:Allocate memory for the error message and use the system message table.
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
        // The message source.(Not used in this case.)
        0,
        // The HRESULT indicating an error.
        hr,
        // Language Flags:Use default.
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        // On return, will point to the error string.
        (LPTSTR) &pvErrorText;,
        // Max message side.We're allocating the buffer dynamically, so not used.
        0,
        // Message arguments.Not used in this case.
        0);

        // This section is for custom error codes that are used by the .NET Alerts client library.
        if (dwChars == 0) {
            switch(hr) {
                case 0x81fd0001:

                    pvErrorText = SysAllocString(
                    L"There was a problem retrieving the .NET Alerts provider credentials from the registry.");
                    break;

                case 0x81fd0002:

                    pvErrorText = SysAllocString(
                    L"A send request was made while waiting for DrainNotifications.");
                    break;

                case 0x81fd0004:

                    pvErrorText = SysAllocString(
                    L"Memory or resource issues caused a failure in the HTTP transport.");
                    break;

                case 0x81fd0191:

                    pvErrorText = SysAllocString(
                    L"Authentication of the .NET Alerts provider failed.");
                    break;

                case 0x81fd01f4:

                    pvErrorText = SysAllocString(
                    L"There was a general delivery failure.");
                    break;

                default:

                    pvErrorText = SysAllocString(
                    L"An unexpected error occurred.");

            }
        }

        // Display the error message, and then free the message buffer.
        if (pvErrorText) {
            wcout  endl  L"Error code description:"  (LPTSTR) pvErrorText  endl;
            LocalFree(pvErrorText);
        }
    
    return;

} // End ShowErrorMessage.

void ShutDown(
    INotificationTransport      *pITransport,
    INotificationsUtility       *pIUtility,
    IMsnNotification        *pIAlert,
    IConnectionPoint        *pIConnectionPoint,
    IConnectionPointContainer   *pIConnectionPointContainer,
    CNotifySink     *pCNotifySink,
    HRESULT           hr) {

    // Release the interfaces
    if (pIUtility) pIUtility->Release();
    if (pIAlert)  pIAlert->Release();
    if (pIConnectionPoint) pIConnectionPoint->Release();
    if (pIConnectionPointContainer) pIConnectionPointContainer->Release();
    if (pITransport) {
        // Be sure to drain the transport object before you release it.
        pITransport->DrainNotifications(0, NULL);
        pITransport->Release();
    }
    delete pCNotifySink;

    // Turn off the COM subsystem.
    CoUninitialize();

    exit(hr);

} // End ShutDown.

情報

ストックされている実装 msnotify.dll
宣言されている場所 msnotify.h および msnotify.idl
最小限のオペレーティング システム Microsoft Windows® 2000

  |