码迷,mamicode.com
首页 > Windows程序 > 详细

Windows UPnP APIs

时间:2020-01-29 21:58:50      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:col   devices   break   bre   sid   unknown   friend   vbscript   inter   

查找设备

<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 << "\n";
            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

 

Windows UPnP APIs

标签:col   devices   break   bre   sid   unknown   friend   vbscript   inter   

原文地址:https://www.cnblogs.com/JebediahKerman/p/Windows_UPnP_APIs.html

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