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
  • 相关阅读:
    谷哥的小弟学后台(29)——动态代理
    HDU
    jni 入门 android的C编程之旅 --->环境搭建&&helloworld
    C# 开发系列(二)
    C# 开发系列(一)
    ajax跨域实现api 接口调用
    dependency injection(2)
    要读的书单
    dependency injection
    php dependency innjection
  • 原文地址:https://www.cnblogs.com/JebediahKerman/p/Windows_UPnP_APIs.html
Copyright © 2011-2022 走看看