码迷,mamicode.com
首页 > 编程语言 > 详细

C++ com 组件的使用

时间:2021-06-28 20:36:02      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:stream   coin   zid   ace   bst   c++   function   use   etl   

// CommonTest.cpp : This file contains the ‘main‘ function. Program execution begins and ends there.

//

 

#include <iostream>

#include <atlbase.h>

#include "mbnapi.h"

 

int main()

{

    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

    if (FAILED(hr))

    {

        return -1;

    }

    CComPtr<IMbnInterfaceManager>  mbnInterfaceMgr = NULL;

    hr = CoCreateInstance(CLSID_MbnInterfaceManager,NULL,CLSCTX_ALL,IID_IMbnInterfaceManager,(void**)&mbnInterfaceMgr);

    if (FAILED(hr))

    {

        return -1;

    }

 

    SAFEARRAY* psa = NULL;

    hr = mbnInterfaceMgr->GetInterfaces(&psa);

    if (FAILED(hr))

    {

        CoUninitialize();

        return -1;

    }

    LONG lLower;

    hr = SafeArrayGetLBound(psa, 1, &lLower);

    if (FAILED(hr))

    {

        CoUninitialize();

        return -1;

    }

 

    LONG lUpper;

    hr = SafeArrayGetUBound(psa, 1, &lUpper);

    if (FAILED(hr))

    {

        CoUninitialize();

        return -1;

    }

 

    CComPtr<IMbnInterface>  pInf = NULL;

    for (LONG l = lLower; l <= lUpper; l++)

    {

        hr = SafeArrayGetElement(psa, &l, (void*)(&pInf));

        if (SUCCEEDED(hr))

        {

            CComPtr<IMbnSubscriberInformation> subscriberInf = NULL;

            hr = pInf->GetSubscriberInformation(&subscriberInf);

            if (SUCCEEDED(hr)) {

                WCHAR tszID[256] = { L‘\0‘ };

                hr = subscriberInf->get_SubscriberID((BSTR*)&tszID);

                if (SUCCEEDED(hr)) {

                    std::wcout << L"SubscriberID: " << tszID <<std::endl;

                }

            }

        }

    }

    SafeArrayDestroy(psa);

    CoUninitialize();

    return 0;

}

 

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu

// Debug program: F5 or Debug > Start Debugging menu

 

// Tips for Getting Started:

//   1. Use the Solution Explorer window to add/manage files

//   2. Use the Team Explorer window to connect to source control

//   3. Use the Output window to see build output and other messages

//   4. Use the Error List window to view errors

//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project

//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

 

C++ com 组件的使用

标签:stream   coin   zid   ace   bst   c++   function   use   etl   

原文地址:https://www.cnblogs.com/bruce1992/p/14943024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!