void MainDialog::FillCategoryList() { // Clear listboxes ClearDeviceList(); ClearFilterList(); if (m_bShowAllCategories) { // Emulate the behavior of GraphEdit by enumerating all // categories in the system DisplayFullCategorySet(); } else { // Fill the category list box with the categories to display, // using the names stored in the CATEGORY_INFO array. // See SysEnumDlg.H for a category description. for (int i=0; i < NUM_CATEGORIES; i++) { m_DeviceList.AddString(categories[i].szName); } // Update listbox title with number of classes SetNumClasses(NUM_CATEGORIES); } }
VOID FltOnDeinitAdapter(PADAPT pAdapt) { PADAPT_FILTER_RSVD pFilterContext; // // 反初始化ADAPT结构中的FilterReserved域 // pFilterContext = (PADAPT_FILTER_RSVD)&pAdapt->FilterReserved; ClearFilterList(pFilterContext); }
HRESULT MainDialog::EnumDMOs(IEnumDMO *pEnumCat) { HRESULT hr=S_OK; int nFilters=0; WCHAR *wszName=0; CLSID clsid; // Clear the current filter list ClearFilterList(); // If there are no filters of a requested type, show default string if (!pEnumCat) { m_FilterList.AddString(TEXT("<< No entries >>")); SetNumFilters(0); return S_OK; } // Enumerate all items associated with the moniker while (pEnumCat->Next(1, &clsid, &wszName, NULL) == S_OK) { nFilters++; // As a precaution, verify that the DMO has a name. If not, // give it a temporary name so that it can be added to the list box // and still have an associated CLSID. size_t len; hr = StringCchLength(wszName, STRSAFE_MAX_CCH, &len); if (SUCCEEDED(hr)) { // Add this DMO's name and CLSID to the listbox AddFilter(wszName, &clsid); } else { AddFilter(TEXT("<< Invalid DMO name >>\0"), &clsid); } CoTaskMemFree(wszName); wszName = 0; } // If no DMOs matched the query, show a default item if (nFilters == 0) { m_FilterList.AddString(TEXT("<< No entries >>")); } // Update count of enumerated filters SetNumFilters(nFilters); return hr; }
void MainDialog::FillCategoryList() { // Clear listboxes ClearDeviceList(); ClearFilterList(); // Fill the category list box with the categories to display, // using the names stored in the DMO_CATEGORY_INFO array. // See DMOEnumDlg.H for a category description. for (int i=0; i < NUM_CATEGORIES; i++) { m_DeviceList.AddString(dmo_categories[i].szName); } // Update listbox title with number of classes SetNumClasses(NUM_CATEGORIES); // Select the first category to show useful information m_DeviceList.Select(0); OnSelchangeListDevices(); }
INT_PTR CALLBACK ServicesDlgProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { static PH_LAYOUT_MANAGER LayoutManager; INT_PTR result; if (result = HandleCommonMessages(hwndDlg, uMsg, wParam, lParam, GetDlgItem(hwndDlg, IDC_LIST), EditingServiceFilterList)) return result; switch (uMsg) { case WM_INITDIALOG: { EditingServiceFilterList = PhCreateList(ServiceFilterList->Count + 10); CopyFilterList(EditingServiceFilterList, ServiceFilterList); PhInitializeLayoutManager(&LayoutManager, hwndDlg); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_LIST), NULL, PH_ANCHOR_ALL); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_MOVEUP), NULL, PH_ANCHOR_TOP | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_MOVEDOWN), NULL, PH_ANCHOR_TOP | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_TEXT), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_INCLUDE), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_EXCLUDE), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_ADD), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_REMOVE), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_RIGHT); PhAddLayoutItem(&LayoutManager, GetDlgItem(hwndDlg, IDC_INFO), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT); AddEntriesToListBox(GetDlgItem(hwndDlg, IDC_LIST), EditingServiceFilterList); } break; case WM_DESTROY: { PPH_STRING string; ClearFilterList(ServiceFilterList); CopyFilterList(ServiceFilterList, EditingServiceFilterList); string = SaveFilterList(ServiceFilterList); PhSetStringSetting2(SETTING_NAME_SERVICE_LIST, &string->sr); PhDereferenceObject(string); ClearFilterList(EditingServiceFilterList); PhDereferenceObject(EditingServiceFilterList); EditingServiceFilterList = NULL; PhDeleteLayoutManager(&LayoutManager); } break; case WM_SIZE: { PhLayoutManagerLayout(&LayoutManager); } break; } return FALSE; }
HRESULT MainDialog::EnumFilters(IEnumMoniker *pEnumCat) { HRESULT hr=S_OK; int nFilters=0; IMoniker *pMoniker = NULL; // Clear the current filter list ClearFilterList(); // If there are no filters of a requested type, show default string if (!pEnumCat) { m_FilterList.AddString(TEXT("<< No entries >>")); SetNumFilters(nFilters); return S_OK; } // Enumerate all items associated with the moniker while (pEnumCat->Next(1, &pMoniker, NULL) == S_OK) { IPropertyBag *pPropBag = NULL; CLSID clsidFilter; VARIANT varName; VARIANT varFilterClsid; VariantInit(&varName); VariantInit(&varFilterClsid); // Associate moniker with a file hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); // Read filter name from property bag if (SUCCEEDED(hr)) { hr = pPropBag->Read(L"FriendlyName", &varName, 0); } // Read filter's CLSID from property bag. This CLSID string will be // converted to a binary CLSID and passed to AddFilter(), which will // add the filter's name to the listbox and its CLSID to the listbox // item's DataPtr item. When the user clicks on a filter name in // the listbox, we'll read the stored CLSID, convert it to a string, // and use it to find the filter's filename in the registry. if (SUCCEEDED(hr)) { // Read CLSID string from property bag hr = pPropBag->Read(L"CLSID", &varFilterClsid, 0); // Add filter name and CLSID to listbox if (SUCCEEDED(hr)) { hr = CLSIDFromString(varFilterClsid.bstrVal, &clsidFilter); } else if (hr == E_PROP_ID_UNSUPPORTED) { clsidFilter = GUID_NULL; // No CLSID is listed. hr = S_OK; } } // Add filter name and filename to listbox if(SUCCEEDED(hr)) { nFilters++; AddFilter(varName.bstrVal, clsidFilter); } VariantClear(&varName); VariantClear(&varFilterClsid); // Cleanup interfaces SAFE_RELEASE(pPropBag); SAFE_RELEASE(pMoniker); } // Update count of enumerated filters SetNumFilters(nFilters); return hr; }
INT_PTR CALLBACK ServicesDlgProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { if (HandleCommonMessages(hwndDlg, uMsg, wParam, lParam, GetDlgItem(hwndDlg, IDC_LIST), EditingServiceFilterList)) return FALSE; switch (uMsg) { case WM_INITDIALOG: { EditingServiceFilterList = PhCreateList(ServiceFilterList->Count + 10); CopyFilterList(EditingServiceFilterList, ServiceFilterList); AddEntriesToListBox(GetDlgItem(hwndDlg, IDC_LIST), EditingServiceFilterList); } break; case WM_DESTROY: { ClearFilterList(EditingServiceFilterList); PhDereferenceObject(EditingServiceFilterList); EditingServiceFilterList = NULL; } break; case WM_COMMAND: { switch (LOWORD(wParam)) { NOTHING; } } break; case WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; switch (header->code) { case PSN_APPLY: { PPH_STRING string; ClearFilterList(ServiceFilterList); CopyFilterList(ServiceFilterList, EditingServiceFilterList); string = SaveFilterList(ServiceFilterList); PhSetStringSetting2(SETTING_NAME_SERVICE_LIST, &string->sr); PhDereferenceObject(string); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR); } return TRUE; } } break; } return FALSE; }
NTSTATUS FltDevIoControl(PDEVICE_OBJECT pDeviceObject, PIRP pIrp) { // 假设失败 NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST; // 取得此IRP(pIrp)的I/O堆栈指针 PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); // 取得I/O控制代码 ULONG uIoControlCode = pIrpStack->Parameters.DeviceIoControl.IoControlCode; // 取得I/O缓冲区指针和它的长度 PVOID pIoBuffer = pIrp->AssociatedIrp.SystemBuffer; ULONG uInSize = pIrpStack->Parameters.DeviceIoControl.InputBufferLength; ULONG uOutSize = pIrpStack->Parameters.DeviceIoControl.OutputBufferLength; ULONG uTransLen = 0; PADAPT pAdapt = NULL; PADAPT_FILTER_RSVD pFilterContext = NULL; POPEN_CONTEXT pOpenContext = pIrpStack->FileObject->FsContext; if(pOpenContext == NULL || (pAdapt = pOpenContext->pAdapt) == NULL) { status = STATUS_INVALID_HANDLE; goto CompleteTheIRP; } pFilterContext = (PADAPT_FILTER_RSVD)&pAdapt->FilterReserved; // // Fail IOCTL If Unbind Is In Progress Fail IOCTL If Adapter Is Powering Down // NdisAcquireSpinLock(&pAdapt->Lock); if( pAdapt->UnbindingInProcess || pAdapt->StandingBy == TRUE) { NdisReleaseSpinLock(&pAdapt->Lock); status = STATUS_INVALID_DEVICE_STATE; goto CompleteTheIRP; } // 当改变数据时,要拥有SpinLock // 最后,处理IO控制代码 switch(uIoControlCode) { case IOCTL_PTUSERIO_QUERY_STATISTICS: // 获取网络活动状态 { uTransLen = sizeof(PassthruStatistics); if(uOutSize < uTransLen) { status = STATUS_BUFFER_TOO_SMALL; break; } NdisMoveMemory(pIoBuffer, &pFilterContext->Statistics, uTransLen); status = STATUS_SUCCESS; } break; case IOCTL_PTUSERIO_RESET_STATISTICS: // 重设网络活动状态 { NdisZeroMemory(&pFilterContext->Statistics, sizeof(PassthruStatistics)); status = STATUS_SUCCESS; } break; case IOCTL_PTUSERIO_ADD_FILTER: // 添加一个过滤规则 { if(uInSize >= sizeof(PassthruFilter)) { DBGPRINT((" 添加一个过滤规则")); status = AddFilterToAdapter(pFilterContext, (PPassthruFilter)pIoBuffer); } else { status = STATUS_INVALID_DEVICE_REQUEST; } } break; case IOCTL_PTUSERIO_CLEAR_FILTER: // 清除过滤规则 { DBGPRINT((" 清除过滤规则")); ClearFilterList(pFilterContext); status = STATUS_SUCCESS; } break; } NdisReleaseSpinLock(&pAdapt->Lock); CompleteTheIRP: if(status == STATUS_SUCCESS) pIrp->IoStatus.Information = uTransLen; else pIrp->IoStatus.Information = 0; pIrp->IoStatus.Status = status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); return status; }