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; }
/** * @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(); } }
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)) { printf("Failed to init disc recorder. Error: 0x%X.\n", hr); } } //Check if it's the right recorder. if (SUCCEEDED(hr)) { SAFEARRAY * mountPoints = NULL; hr = tmpRecorder->get_VolumePathNames(&mountPoints); if (FAILED(hr)) { printf("Unable to get mount points. Error: 0x%X.\n", hr); } else if (mountPoints->rgsabound[0].cElements == 0) { printf("\tMount Point: *** NO MOUNT POINTS FOR RECORDER ***\n"); } else { VARIANT* tmp = (VARIANT*)(mountPoints->pvData); for (ULONG i = 0; i < mountPoints->rgsabound[0].cElements; i++) { if ( _wcsnicmp(Arguments[0], tmp[i].bstrVal, 2) == 0 ) { recorderFound = TRUE; break; } } } SafeArrayDestroyDataAndNull(mountPoints); } } } } // copy to caller or release recorder if (SUCCEEDED(hr) && recorderFound) { *Recorder = tmpRecorder; } else { validArgument = FALSE; ReleaseAndNull(tmpRecorder); } // all other cleanup ReleaseAndNull(tmpDiscMaster); } return validArgument; }