当前位置: 首页>>代码示例>>C++>>正文


C++ IEnumVARIANT类代码示例

本文整理汇总了C++中IEnumVARIANT的典型用法代码示例。如果您正苦于以下问题:C++ IEnumVARIANT类的具体用法?C++ IEnumVARIANT怎么用?C++ IEnumVARIANT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IEnumVARIANT类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DEFINE_FINALIZE

DEFINE_FINALIZE() {

//	if ( obj == jl::Host::getJLHost(fop->runtime()).getCachedProto(JL_THIS_CLASS_NAME) ) // we are finilizing the prototype ?
//		return;

    IEnumVARIANT *ienumv = (IEnumVARIANT*)JL_GetPrivateFromFinalize(obj);
    if ( !ienumv )
        return;
    ienumv->Release();
}
开发者ID:BenitoJedai,项目名称:jslibs,代码行数:10,代码来源:comenum.cpp

示例2: AFX_MANAGE_STATE

STDMETHODIMP CEDBS_Linien::get__NewEnum(IUnknown **pVal)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

 HRESULT hResult;
 CComObject<CEDBS_LinienENUM> *pobjENUM;
 IEnumVARIANT *pIENUM;

	hResult = CComObject<CEDBS_LinienENUM>::CreateInstance(&pobjENUM); 
	pobjENUM->mpobjsLinien = this;
	hResult = pobjENUM->QueryInterface(IID_IUnknown,(void**)pVal);
	
	pIENUM = NULL;
	hResult = pobjENUM->QueryInterface(IID_IEnumVARIANT,(void**)&pIENUM);
	pIENUM->Reset();

	return S_OK;
}
开发者ID:gsaralji,项目名称:TRiAS,代码行数:18,代码来源:EDBS_Linien.cpp

示例3: CleanPortMaps

/**
 * @brief	Updates information about port maps on router.
 */
void UpnpNatAction::UpdateInfo()
{
	HRESULT hResult;

	// Cleanup old port map in case this is an update
	CleanPortMaps();

	// Retrieve current port mappings
	hResult = nat->get_StaticPortMappingCollection(&portMapCollection);
	_ErrorException((hResult != S_OK), "retrieving current port mappings (!= S_OK)", hResult, __LINE__, __FILE__);
	_ErrorException((portMapCollection == NULL), "retrieving current port mappings (NULL)", NULL, __LINE__, __FILE__);

	// Scan through list and load port maps into vector
	// Code is based on MSDN sample
	IUnknown * ptrUnk = NULL;
	hResult = portMapCollection->get__NewEnum(&ptrUnk);
	if (SUCCEEDED(hResult))
	{
		IEnumVARIANT * ptrEnumVar = NULL;
		hResult = ptrUnk->QueryInterface(IID_IEnumVARIANT, (void **) &ptrEnumVar);
		if (SUCCEEDED(hResult))
		{
			VARIANT varCurDevice;
			VariantInit(&varCurDevice);
			ptrEnumVar->Reset();
			// Loop through each port map in the collection
			while (S_OK == ptrEnumVar->Next(1, &varCurDevice, NULL))
			{
				IStaticPortMapping * ptrPortMap = NULL;
				IDispatch * pdispDevice = V_DISPATCH(&varCurDevice);
				if (SUCCEEDED(pdispDevice->QueryInterface(IID_IStaticPortMapping, (void **) &ptrPortMap)))
				{
					// Add port map to vector
					UpnpNatPortMapAction * newPortMap = new (nothrow)UpnpNatPortMapAction(ptrPortMap);
					Utility::DynamicAllocCheck(newPortMap,__LINE__,__FILE__);
					portMaps.Add(newPortMap);						
				}
				VariantClear(&varCurDevice);
			}
			ptrEnumVar->Release();
		}
		ptrUnk->Release();
	}
}
开发者ID:watfordxp,项目名称:MikeNet,代码行数:47,代码来源:UpnpNatAction.cpp

示例4: showDebug

HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accSelection(VARIANT *pvarChildren)
{
#ifdef DEBUG_SHOW_ATCLIENT_COMMANDS
    showDebug(__FUNCTION__, accessible);
#endif //DEBUG_SHOW_ATCLIENT_COMMANDS
    if (!accessible->isValid())
        return E_FAIL;

    int cc = accessible->childCount();
    QVector<int> sel(cc);
    int selIndex = 0;
    for (int i = 1; i <= cc; ++i) {
        QAccessibleInterface *child = 0;
        int i2 = accessible->navigate(Child, i, &child);
        bool isSelected = false;
        if (child) {
            isSelected = child->state(0) & Selected;
            delete child;
            child = 0;
        } else {
            isSelected = accessible->state(i2) & Selected;
        }
        if (isSelected)
            sel[selIndex++] = i;
    }
    sel.resize(selIndex);
    if (sel.isEmpty()) {
        (*pvarChildren).vt = VT_EMPTY;
        return S_FALSE;
    }
    if (sel.size() == 1) {
        (*pvarChildren).vt = VT_I4;
        (*pvarChildren).lVal = sel[0];
        return S_OK;
    }
    IEnumVARIANT *iface = new QWindowsEnumerate(sel);
    IUnknown *uiface;
    iface->QueryInterface(IID_IUnknown, (void**)&uiface);
    (*pvarChildren).vt = VT_UNKNOWN;
    (*pvarChildren).punkVal = uiface;

    return S_OK;
}
开发者ID:GodFox,项目名称:qtopia-ezx,代码行数:43,代码来源:qaccessible_win.cpp

示例5: VerifyIntegerEnumeration

extern "C" DLL_EXPORT HRESULT STDMETHODCALLTYPE VerifyIntegerEnumeration(IDispatch* pDisp, int start, int count)
{
    DISPPARAMS params{};
    VARIANT result;
    HRESULT hr = pDisp->Invoke(
        DISPID_NEWENUM,
        IID_NULL,
        LOCALE_USER_DEFAULT,
        DISPATCH_METHOD | DISPATCH_PROPERTYGET,
        &params,
        &result,
        NULL,
        NULL
    );

    if (FAILED(hr))
    {
        return hr;
    }

    if(!((V_VT(&result) == VT_UNKNOWN) || (V_VT(&result) == VT_DISPATCH)))
    {
        return E_UNEXPECTED;
    }

    IEnumVARIANT* pEnum;

    hr = V_UNKNOWN(&result)->QueryInterface<IEnumVARIANT>(&pEnum);

    if (FAILED(hr))
    {
        return hr;
    }

    hr = VerifyIntegerEnumerator(pEnum, start, count);

    pEnum->Release();

    return hr;
}
开发者ID:A-And,项目名称:coreclr,代码行数:40,代码来源:IEnumeratorNative.cpp

示例6: discover

static int discover(opal_list_t* nodelist, ICluster* pCluster)
{
    int ret = ORTE_ERROR;
    int32_t nodeid;
    orte_node_t *node;
    opal_list_item_t* item;
    opal_list_t new_nodes;
    struct timeval start, stop;

    HRESULT hr = S_OK;  
    long idle_processors = 0;
    IClusterEnumerable* pNodesCollection = NULL;
    IEnumVARIANT* pNodes = NULL;
    INode* pNode = NULL;
    BSTR node_name = NULL, node_arch = NULL;
    VARIANT var;
    NodeStatus Status;
    size_t len;

    /* check for timing request - get start time if so */
    if (orte_timing) {
        gettimeofday(&start, NULL);
    }
    
    /* Get the collection of nodes. */
    hr = pCluster->get_ComputeNodes(&pNodesCollection);
    if (FAILED(hr)) {
        ras_get_cluster_message(pCluster);
        OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                            "ras:ccp:pCluster->get_ComputeNodes failed."));
        return ORTE_ERROR;
    }

    /* Get the enumerator used to iterate through the collection. */
    hr = pNodesCollection->GetEnumerator(&pNodes);
    if (FAILED(hr)) {
        ras_get_cluster_message(pCluster);
        OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                            "ras:ccp:pNodesCollection->GetEnumerator failed."));
        return ORTE_ERROR;
    }

    VariantInit(&var);

    /* Construct new node list. */
    OBJ_CONSTRUCT(&new_nodes, opal_list_t);
    nodeid=0;

    /* Loop through the collection. */
    while (hr = pNodes->Next(1, &var, NULL) == S_OK) {
        var.pdispVal->QueryInterface(IID_INode, reinterpret_cast<void **> (&pNode));

        /* Check wether the node is ready. 
         * There are four states:
         *          NodeStatus_Ready = 0,
         *          NodeStatus_Paused = 1,
         *          NodeStatus_Unreachable = 2, probably not a windows cluster node.
         *          NodeStatus_PendingApproval = 3
         */
        hr = pNode->get_Status(&Status);
        if (FAILED(hr)) {
            OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                                "ras:ccp:pNode->get_Status failed."));
            ret = ORTE_ERROR;
            goto cleanup;
        }

        /* Get available number of processors on each node. */
        hr = pNode->get_NumberOfIdleProcessors(&idle_processors);
        if (FAILED(hr)) {
            OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                                "ras:ccp:pNode->get_NumberOfIdleProcessors failed."));
            ret = ORTE_ERROR;
            goto cleanup;
        }

        /* Do we have enough processors on the available nodes? 
         * Question: How do we get the required number of processors?
         */
        if ( (Status == NodeStatus_Ready) && (idle_processors > 0) ) {

            /* Get node name. */
            hr = pNode->get_Name(&node_name);
            if (FAILED(hr)) {
                OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                                    "ras:ccp:pNode->get_Name failed."));
                ret = ORTE_ERROR;
                goto cleanup;
            }

            /* Get node processor architecture. */
            hr = pNode->get_ProcessorArchitecture(&node_arch);
            if (FAILED(hr)) {
                OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output,
                                    "ras:ccp:pNode->get_ProcessorArchitecture failed."));
                ret = ORTE_ERROR;
                goto cleanup;
            }

            /* Prevent duplicated nodes in the list*/
//.........这里部分代码省略.........
开发者ID:315234,项目名称:OpenFOAM-2.2.x-OSX,代码行数:101,代码来源:ras_ccp_module.c

示例7: RecursiveIsMember

BOOL RecursiveIsMember(IADsGroup * pADsGroup,LPWSTR pwszMemberGUID,LPWSTR pwszMemberPath, 
                                             BOOL bVerbose, LPOLESTR  pwszUser, LPOLESTR pwszPassword)
{
    HRESULT         hr                = S_OK;     // COM Result Code
    IADsMembers *   pADsMembers       = NULL;     // Ptr to Members of the IADsGroup
    BOOL            fContinue         = TRUE;     // Looping Variable
    IEnumVARIANT *  pEnumVariant      = NULL;     // Ptr to the Enum variant
    IUnknown *      pUnknown          = NULL;     // IUnknown for getting the ENUM initially
    VARIANT         VariantArray[FETCH_NUM];      // Variant array for temp holding returned data
    ULONG           ulElementsFetched = NULL;     // Number of elements retrieved
    BSTR            bsGroupPath       = NULL;
    BOOL            bRet              = FALSE;

    if(!pADsGroup || !pwszMemberGUID || !pwszMemberPath)
    {
        return FALSE;
    }
 
    // Get the path of the object passed in
    hr = pADsGroup->get_ADsPath(&bsGroupPath);
 
    if (!SUCCEEDED(hr))
        return hr;
 
    if (bVerbose)
    {
        WCHAR pwszOutput[2048];
        wsprintf(pwszOutput,L"Checking the Group:\n\n%s\n\n for the member:\n\n%s\n\n",bsGroupPath,pwszMemberPath);
        PrintBanner(pwszOutput);
    }
 
    // Get an interface pointer to the IADsCollection of members
    hr = pADsGroup->Members(&pADsMembers);
 
    if (SUCCEEDED(hr))
    {
        // Query the IADsCollection of members for a new ENUM Interface
        // Be aware that the enum comes back as an IUnknown *
        hr = pADsMembers->get__NewEnum(&pUnknown);
 
        if (SUCCEEDED(hr))
        {
            // QI the IUnknown * for an IEnumVARIANT interface
            hr = pUnknown->QueryInterface(IID_IEnumVARIANT, (void **)&pEnumVariant);
 
            if (SUCCEEDED(hr))
            {
                // While have not hit errors or end of data....
                while (fContinue) 
                {
                   ulElementsFetched = 0;
                    // Get a "batch" number of group members-number of rows specified by FETCH_NUM
                    hr = ADsEnumerateNext(pEnumVariant, FETCH_NUM, VariantArray, &ulElementsFetched);
 
                    if (ulElementsFetched )
                    {
                        // Loop through the current batch-printing the path for each member.
                        for (ULONG i = 0; i < ulElementsFetched; i++ ) 
                        {
                            IDispatch * pDispatch         = NULL; // ptr for holding dispath of element
                            BSTR        bstrCurrentPath   = NULL; // Holds path of object
                            BSTR        bstrGuidCurrent   = NULL; // Holds path of object
                            IDirectoryObject * pIDOCurrent = NULL;// Holds the current object          
 
                            // Get the dispatch ptr for the variant
                            pDispatch = VariantArray[i].pdispVal;
//                            assert(HAS_BIT_STYLE(VariantArray[i].vt,VT_DISPATCH));
 
                            // Get the IADs interface for the "member" of this group
                            hr = pDispatch->QueryInterface(IID_IDirectoryObject,
                                                           (VOID **) &pIDOCurrent ) ;
 
                            if (SUCCEEDED(hr))
                            {
                                // Get the GUID for the current object
                                hr = GetObjectGuid(pIDOCurrent,bstrGuidCurrent);
 
                                if (FAILED(hr))
                                    return hr;
 
                                IADs * pIADsCurrent = NULL;
 
                                // Retrieve the IADs Interface for the current object
                                hr = pIDOCurrent->QueryInterface(IID_IADs,(void**)&pIADsCurrent);
                                if (FAILED(hr))
                                    return hr;
 
                                // Get the ADsPath property for this member
                                hr = pIADsCurrent->get_ADsPath(&bstrCurrentPath);
 
                                if (SUCCEEDED(hr))
                                {
                                    if (bVerbose)
                                        wprintf(L"Comparing:\n\n%s\nWITH:\n%s\n\n",bstrGuidCurrent,pwszMemberGUID);
                                    
                                    // Verify that the member of this group is Equal to passed.
                                    if (_wcsicmp(bstrGuidCurrent,pwszMemberGUID)==0)
                                    {
                                        if (bVerbose)
                                            wprintf(L"!!!!!Object:\n\n%s\n\nIs a member of\n\n%s\n\n",pwszMemberPath,bstrGuidCurrent);   
//.........这里部分代码省略.........
开发者ID:copilot-com,项目名称:CopilotVNC,代码行数:101,代码来源:ldapAuth.cpp

示例8: GetParameters

BOOLEAN
GetParameters(
    IN  DWORD           Count,
    IN  WCHAR*          Arguments[],
    OUT IDiscRecorder2** Recorder,
    OUT VARIANT_BOOL*   FullErase
    )
{
    BOOLEAN validArgument = TRUE;

    if ((Count < 1) || (Count > 2))
    {
        validArgument = FALSE;
    }

    if (validArgument && (Arguments[0][1] != ':'))
    {
        validArgument = FALSE;
    }

    if (validArgument && (Count == 2))
    {
        if ( _wcsnicmp(Arguments[1], (L"-fullerase"), strlen("-fullerase")) == 0 )
        {
            *FullErase = VARIANT_TRUE;
        }
        else
        {
            validArgument = FALSE;
        }
    }

    //Try to retrieve the recorder.
    if (validArgument)
    {
        HRESULT         hr = S_OK;
        IDiscMaster2*   tmpDiscMaster = NULL;
        IEnumVARIANT*   tmpRecorderEnumerator = NULL;
        IDiscRecorder2* tmpRecorder = NULL;
        VARIANT         tmpUniqueId;
        BOOLEAN         recorderFound = FALSE;

        // create the disc master object
        if (SUCCEEDED(hr))
        {
            hr = CoCreateInstance(CLSID_MsftDiscMaster2,
                                  NULL, 
                                  CLSCTX_ALL,
                                  IID_PPV_ARGS(&tmpDiscMaster)
                                  );
            if (FAILED(hr))
            {
                printf("Failed to Create DiscMaster. Error: 0x%X.\n", hr);
            }
        }

        // get a new enumerator for the disc recorders
        if (SUCCEEDED(hr))
        {        
            hr = tmpDiscMaster->get__NewEnum(&tmpRecorderEnumerator);
            if (FAILED(hr))
            {
                printf("Failed get__NewEnum. Error: 0x%X.\n", hr);
            }
        }

        // Reset the enumerator to the beginning
        if (SUCCEEDED(hr))
        {
            hr = tmpRecorderEnumerator->Reset();
            if (FAILED(hr))
            {
                printf("Failed to reset enumerator. Error: 0x%X.\n", hr);
            }
        }

        // request just that one recorder's BSTR
        if (SUCCEEDED(hr))
        {
            while (SUCCEEDED(hr) && !recorderFound)
            {
                hr = tmpRecorderEnumerator->Next(1, &tmpUniqueId, NULL);
                if (SUCCEEDED(hr))
                {
                    // Create a new IDiscRecorder2
                    hr = CoCreateInstance(CLSID_MsftDiscRecorder2,
                                          NULL, 
                                          CLSCTX_ALL,
                                          IID_PPV_ARGS(&tmpRecorder)
                                          );
                    if (FAILED(hr))
                    {
                        printf("Failed CoCreateInstance for DiscRecorder. Error: 0x%X.\n", hr);
                    }

                    // Initialize it with the provided BSTR
                    if (SUCCEEDED(hr))
                    {
                        hr = tmpRecorder->InitializeDiscRecorder(tmpUniqueId.bstrVal);
                        if (FAILED(hr))
//.........这里部分代码省略.........
开发者ID:Ippei-Murofushi,项目名称:WindowsSDK7-Samples,代码行数:101,代码来源:EraseTest.cpp

示例9: dprintf

HRESULT
WindowsFirewallHelper::removeByBasename( const char *name ) {
	
	HRESULT hr = S_OK;
	 
	IUnknown* pUnknown = NULL;
	IEnumVARIANT* pEnum = NULL;
    INetFwAuthorizedApplication* fwApp = NULL;
 
	bool result = true;
	long count;
	unsigned long cnt;
	int i;
	VARIANT v;

	if ( ! ready() ) {
		return S_FALSE;
	}

	hr = fwApps->get__NewEnum(&pUnknown);
	if ( hr != S_OK ) {
		dprintf(D_ERROR, "Failed to get enumerator for Authorized "
				"Applications (err=%x)\n", hr);
		return hr;
	}

	hr = fwApps->get_Count(&count);
	if ( hr != S_OK ) {
		dprintf(D_ERROR, "Failed to get count of Authorized "
				"Applications (err=%x)\n", hr);
		return hr;
	}

	hr = pUnknown->QueryInterface(IID_IEnumVARIANT, (void**)&pEnum);
	if ( hr != S_OK ) {
		if ( hr == E_NOINTERFACE ) {
			dprintf(D_ERROR, "Failed to QueryInterface for trusted "
					"applications. Interface not supported.\n");
		} else {
			dprintf(D_ERROR, "Failed to QueryInterface for trusted "
				   "applications. (err=%x)\n", hr);
		}
		return hr;
	}

	for (i=0; i<count; i++) {
		BSTR str = NULL;
		size_t len;
		char *tmp;
	    const char *bn;

		hr = pEnum->Next(1, &v, &cnt);
		// interesting tidbit: Microsoft says Enum->Next() function
		// either returns S_OK or S_FALSE. Funny, on Win2k3 SP1
		// it returns 0x80020008, or Bad Variable Type. Sigh.
		if ( hr != S_OK ) {
			// no more elements. stop.
			hr = S_FALSE;
			break;
		}

		fwApp = (INetFwAuthorizedApplication*)v.byref;

		fwApp->get_ProcessImageFileName(&str);

		// This should not be printing to stdout, but if you are
		// reading this and think it is necessary to print these 
		// executable names then dprintf() them.
		// printf("Result is %lS\n", str);

		len = wcslen(str);
		tmp = (char*) malloc((len*2+1) * sizeof(char));
		ASSERT(tmp);
		sprintf(tmp, "%S", str);

		bn = condor_basename(tmp);

		if ( 0 == strcasecmp(bn, name) ) {
			
			// basenames match, so remove it from the list.
			
			hr = removeTrusted(tmp);
		}
		free(tmp);

		SysFreeString(str);

		if (hr == E_ACCESSDENIED) {
			// don't have enough privilege to remove, so don't bother to keep trying.
			break;
		}
	}

	return hr;
}
开发者ID:bbockelm,项目名称:htcondor,代码行数:95,代码来源:firewall.WINDOWS.cpp

示例10: ASSERT

void CDlgIADsSecurityDescriptor::PopulateACL(IADsAccessControlList * pACL)
{
	ASSERT( pACL );
	HRESULT hr;
	ULONG   lFetch;

	IEnumVARIANT *pEnum;
	LPUNKNOWN     pUnk;
	VARIANT       var;
	IDispatch	 *pDisp;
	BSTR		  bstr;
	CString		  s;

	IADsAccessControlEntry *pACE;
	
	
	m_cACEList.ResetContent();
	ResetAcePtr();

	
	hr = pACL->get__NewEnum( &pUnk );
	if ( !SUCCEEDED(hr) )
	{
		return;
	}

	hr = pUnk->QueryInterface( IID_IEnumVARIANT, (void**) &pEnum );
	if ( !SUCCEEDED(hr) )
	{
		return;
	}

	hr = pEnum->Next( 1, &var, &lFetch );
	
	while( hr == S_OK )
	{		
		if ( lFetch == 1 )
		{
			if ( VT_DISPATCH != V_VT(&var) )
			{
				break;
			}
		

		   	pDisp = V_DISPATCH(&var);
			///////////////////////////
			// Get the ACE
			/////////////////////////////
			hr = pDisp->QueryInterface( IID_IADsAccessControlEntry, (void**)&pACE ); 
			if ( SUCCEEDED(hr) )
			{
				pACE->get_Trustee(&bstr);
				s = bstr;
				SysFreeString(bstr);
				m_cACEList.AddString( s );
				m_acePtrList.AddTail( pACE ); //save the pointer for future use, 
				                           // we don't need to Release() it.

			}

			VariantClear(&var);
		}
		hr = pEnum->Next( 1, &var, &lFetch );
		
    };



	pACL->Release();
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:70,代码来源:security.cpp

示例11: main

int __cdecl main()
{
    HRESULT hrComInit = S_OK;
    HRESULT hr = S_OK;

    ULONG cFetched = 0; 
    CComVariant var;

    IUnknown *pEnumerator;
    IEnumVARIANT* pVariant = NULL;

    INetFwPolicy2 *pNetFwPolicy2 = NULL;
    INetFwRules *pFwRules = NULL;
    INetFwRule *pFwRule = NULL;

    long fwRuleCount;

    // Initialize COM.
    hrComInit = CoInitializeEx(
                    0,
                    COINIT_APARTMENTTHREADED
                    );

    // Ignore RPC_E_CHANGED_MODE; this just means that COM has already been
    // initialized with a different mode. Since we don't care what the mode is,
    // we'll just use the existing mode.
    if (hrComInit != RPC_E_CHANGED_MODE)
    {
        if (FAILED(hrComInit))
        {
            wprintf(L"CoInitializeEx failed: 0x%08lx\n", hrComInit);
            goto Cleanup;
        }
    }

    // Retrieve INetFwPolicy2
    hr = WFCOMInitialize(&pNetFwPolicy2);
    if (FAILED(hr))
    {
        goto Cleanup;
    }

    // Retrieve INetFwRules
    hr = pNetFwPolicy2->get_Rules(&pFwRules);
    if (FAILED(hr))
    {
        wprintf(L"get_Rules failed: 0x%08lx\n", hr);
        goto Cleanup;
    }

    // Obtain the number of Firewall rules
    hr = pFwRules->get_Count(&fwRuleCount);
    if (FAILED(hr))
    {
        wprintf(L"get_Count failed: 0x%08lx\n", hr);
        goto Cleanup;
    }
    
    wprintf(L"The number of rules in the Windows Firewall are %d\n", fwRuleCount);

    // Iterate through all of the rules in pFwRules
    pFwRules->get__NewEnum(&pEnumerator);

    if(pEnumerator)
    {
        hr = pEnumerator->QueryInterface(__uuidof(IEnumVARIANT), (void **) &pVariant);
    }

    while(SUCCEEDED(hr) && hr != S_FALSE)
    {
        var.Clear();
        hr = pVariant->Next(1, &var, &cFetched);

        if (S_FALSE != hr)
        {
            if (SUCCEEDED(hr))
            {
                hr = var.ChangeType(VT_DISPATCH);
            }
            if (SUCCEEDED(hr))
            {
                hr = (V_DISPATCH(&var))->QueryInterface(__uuidof(INetFwRule), reinterpret_cast<void**>(&pFwRule));
            }

            if (SUCCEEDED(hr))
            {
                // Output the properties of this rule
                DumpFWRulesInCollection(pFwRule);
            }
        }
    }
 
Cleanup:

    // Release pFwRule
    if (pFwRule != NULL)
    {
        pFwRule->Release();
    }

//.........这里部分代码省略.........
开发者ID:Ippei-Murofushi,项目名称:WindowsSDK7-Samples,代码行数:101,代码来源:EnumerateFirewallRules.cpp

示例12: DoTheWork

HRESULT DoTheWork (INetSharingManager * pNSM)
{   // add a port mapping to every firewalled or shared connection

    INetSharingEveryConnectionCollection * pNSECC = NULL;
    HRESULT hr = pNSM->get_EnumEveryConnection (&pNSECC);
    int LastErrorCode = 0;
    if (!pNSECC)
        return ICS_Error_FailGetEvery;
    else {

        // enumerate connections
        IEnumVARIANT * pEV = NULL;
        IUnknown * pUnk = NULL;
        hr = pNSECC->get__NewEnum (&pUnk);
        if (pUnk) {
            hr = pUnk->QueryInterface (__uuidof(IEnumVARIANT),
                                       (void**)&pEV);
            pUnk->Release();
        }else{
            return ICS_Error_FailGetNewEnum;
        }
        if (pEV) {
            VARIANT v;
            VariantInit (&v);
            while (S_OK == pEV->Next (1, &v, NULL)) {
                if (V_VT (&v) == VT_UNKNOWN) {
                    INetConnection * pNC = NULL;
                    V_UNKNOWN (&v)->QueryInterface
                            (__uuidof(INetConnection),
                             (void**)&pNC);
                    if (pNC) {
                        INetConnectionProps * pNCP = NULL;
                        pNSM->get_NetConnectionProps (pNC, &pNCP);
                        if (!pNCP)
                            wprintf (L"failed to get NetConnectionProps!\r\n");
                                     else {
                                         // check properties for firewalled or shared connection
                                         NETCON_MEDIATYPE MediaType;
                                         pNCP->get_MediaType(&MediaType);
                                         NETCON_STATUS Status;
                                         pNCP->get_Status(&Status);
                                         BSTR DevName;
                                         pNCP->get_DeviceName(&DevName);

                                         if (MediaType & (NCM_LAN | NCM_SHAREDACCESSHOST_LAN | NCM_PHONE)
                                                 && Status == NCS_CONNECTED
                                                 && QString(_com_util::ConvertBSTRToString(DevName)).indexOf("hosted network", 0, Qt::CaseInsensitive)==-1
                                                 && QString(_com_util::ConvertBSTRToString(DevName)).indexOf("virtual", 0, Qt::CaseInsensitive)==-1
                                                 && QString(_com_util::ConvertBSTRToString(DevName)).indexOf("teamviewer", 0, Qt::CaseInsensitive)==-1) {
                                                 // got a shared/firewalled connection
                                                 INetSharingConfiguration * pNSC = NULL;
                                                 hr = pNSM->get_INetSharingConfigurationForINetConnection (pNC, &pNSC);
                                                 if (!pNSC)
                                                 wprintf (L"can't make INetSharingConfiguration object!\r\n");
                                                 else {
                                                     hr = pNSC->EnableSharing(ICSSHARINGTYPE_PRIVATE);
                                                     if(hr!=S_OK){
                                                         LastErrorCode = ICS_Error_EnableSharing;
                                                     }else{
                                                         BSTR Name;
                                                         pNCP->get_Name(&Name);
                                                         QMessageBox msg;
                                                         msg.setText(QString("Network: %1 %2 %3").arg(_com_util::ConvertBSTRToString(Name)).arg(_com_util::ConvertBSTRToString(DevName)).arg(Status));
                                                         msg.exec();
                                                         return 0;
                                                     }
                                                     pNSC->Release();
                                                 }
                                         }
                                         pNCP->Release();
                                     }
                                     pNC->Release();
                    }
                }
                VariantClear (&v);
            }
            pEV->Release();
        }else{
            return ICS_Error_FailGetEnumVariant;
        }
        pNSECC->Release();
    }
    if(LastErrorCode!=0) return LastErrorCode;
    return hr;
}
开发者ID:OlexandrI,项目名称:Amalthea-WiFi,代码行数:85,代码来源:mainwindow.cpp


注:本文中的IEnumVARIANT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。