zoukankan      html  css  js  c++  java
  • C++ com 组件的使用

    // 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'' };

                    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

  • 相关阅读:
    Docker 部署 ELK 收集 Nginx 日志
    编译安装python3事出错:
    Linux 系统中部署 LNMP 高可用负载均衡架构集群实现动态博客
    [转载]oracle调用JAVA授权问题
    [转载]浏览器跨域
    [转载]ftp和http区别
    [转载]oracle xml操作
    [转载]Oracle中TO_NUMBER()函数的用法
    [转载]桥接与NAT
    [转载]Oracle中动态SQL详解
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14943024.html
Copyright © 2011-2022 走看看