zoukankan      html  css  js  c++  java
  • Windows UPnP APIs

    查找设备

    <C++>

    #include <iostream>
    #include <Windows.h>
    #include <UPnP.h>
    #pragma comment(lib, "ole32.lib")
    #pragma comment(lib, "oleaut32.lib")
    
    using namespace std;
    
    int main()
    {
        do
        {
            if (CoInitialize(NULL) != S_OK)
            {
                break;
            }
            IUPnPDeviceFinder *pDeviceFinder = NULL;
            if (CoCreateInstance(CLSID_UPnPDeviceFinder,
                                 NULL,
                                 CLSCTX_INPROC_SERVER,
                                 IID_IUPnPDeviceFinder,
                                 (void **)&pDeviceFinder) != S_OK)
            {
                break;
            }
            BSTR bstrSsdpAll = SysAllocString(L"ssdp:all");
            IUPnPDevices *pDevices = NULL;
            if (pDeviceFinder->FindByType(bstrSsdpAll, 0, &pDevices) != S_OK)
            {
                break;
            }
            SysFreeString(bstrSsdpAll);
            IEnumVARIANT *pEnumVar = NULL;
            if (pDevices->get__NewEnum((IUnknown **)&pEnumVar) != S_OK)
            {
                break;
            }
            if (((IUnknown *)pEnumVar)->QueryInterface(IID_IEnumVARIANT, (void **)&pEnumVar) != S_OK)
            {
                break;
            }
            VARIANT varCurDevice;
            VariantInit(&varCurDevice);
            pEnumVar->Reset();
            while (pEnumVar->Next(1, &varCurDevice, NULL) == S_OK)
            {
                IUPnPDevice *pDevice = NULL;
                IDispatch *pdispDevice = V_DISPATCH(&varCurDevice);
                if (pdispDevice->QueryInterface(IID_IUPnPDevice, (void **)&pDevice) != S_OK)
                {
                    continue;
                }
                BSTR bstrName = NULL;
                BSTR bstrType = NULL;
                if (pDevice->get_FriendlyName(&bstrName) != S_OK)
                {
                    continue;
                }
                pDevice->get_Type(&bstrType);
                wcout << bstrName << " " << bstrType << "
    ";
                SysFreeString(bstrName);
                SysFreeString(bstrType);
            }
        } while (false);
        CoUninitialize();
    }

     <VBScript>

    Dim deviceFinder
    Set deviceFinder = CreateObject("UPnP.UPnPDeviceFinder")
    Dim devices
    Set devices = deviceFinder.FindByType("ssdp:all", 0)
    For Each device In devices
        WScript.Echo device.FriendlyName + " " + device.Type
    Next
  • 相关阅读:
    MySql中把一个表的数据插入到另一个表中的实现代码
    mysql中key 、primary key 、unique key 与index区别
    Git忽略规则和.gitignore规则不生效的解决办法
    将从数据库获取的秒数转换为00:00:00格式
    sql查询平均下单时间
    Intersection of Two Linked Lists
    Insertion Sort List
    Delete Node in a Linked List
    Copy List with Random Pointer
    Contains Duplicate
  • 原文地址:https://www.cnblogs.com/JebediahKerman/p/Windows_UPnP_APIs.html
Copyright © 2011-2022 走看看