📄 inf_wizard.c
字号:
device->vid = 0x12AB; device->pid = 0x12AB; } if(!device->manufacturer[0]) strcpy(device->manufacturer, "Insert manufacturer name"); if(!device->description[0]) strcpy(device->description, "Insert device description"); if(notification_handle_hub) UnregisterDeviceNotification(notification_handle_hub); if(notification_handle_dev) UnregisterDeviceNotification(notification_handle_dev); device_list_clean(list); EndDialog(dialog, ID_DIALOG_2); return TRUE; case ID_BUTTON_BACK: device_list_clean(list); if(notification_handle_hub) UnregisterDeviceNotification(notification_handle_hub); if(notification_handle_dev) UnregisterDeviceNotification(notification_handle_dev); EndDialog(dialog, ID_DIALOG_0); return TRUE ; case ID_BUTTON_CANCEL: case IDCANCEL: device_list_clean(list); if(notification_handle_hub) UnregisterDeviceNotification(notification_handle_hub); if(notification_handle_dev) UnregisterDeviceNotification(notification_handle_dev); EndDialog(dialog, 0); return TRUE ; } } return FALSE;}BOOL CALLBACK dialog_proc_2(HWND dialog, UINT message, WPARAM w_param, LPARAM l_param){ static device_context_t *device = NULL; char tmp[MAX_PATH]; switch(message) { case WM_INITDIALOG: device = (device_context_t *)l_param; if(device) { memset(tmp, 0, sizeof(tmp)); sprintf(tmp, "0x%04X", device->vid); SetWindowText(GetDlgItem(dialog, ID_TEXT_VID), tmp); memset(tmp, 0, sizeof(tmp)); sprintf(tmp, "0x%04X", device->pid); SetWindowText(GetDlgItem(dialog, ID_TEXT_PID), tmp); SetWindowText(GetDlgItem(dialog, ID_TEXT_MANUFACTURER), device->manufacturer); SetWindowText(GetDlgItem(dialog, ID_TEXT_DEV_NAME), device->description); } return TRUE; case WM_COMMAND: switch(LOWORD(w_param)) { case ID_BUTTON_NEXT: memset(device, 0, sizeof(*device)); GetWindowText(GetDlgItem(dialog, ID_TEXT_MANUFACTURER), device->manufacturer, sizeof(tmp)); GetWindowText(GetDlgItem(dialog, ID_TEXT_DEV_NAME), device->description, sizeof(tmp)); GetWindowText(GetDlgItem(dialog, ID_TEXT_VID), tmp, sizeof(tmp)); sscanf(tmp, "0x%04x", &device->vid); GetWindowText(GetDlgItem(dialog, ID_TEXT_PID), tmp, sizeof(tmp)); sscanf(tmp, "0x%04x", &device->pid); if(save_file(dialog, device)) EndDialog(dialog, ID_DIALOG_3); return TRUE ; case ID_BUTTON_BACK: EndDialog(dialog, ID_DIALOG_1); return TRUE ; case ID_BUTTON_CANCEL: case IDCANCEL: EndDialog(dialog, 0); return TRUE ; } } return FALSE;}BOOL CALLBACK dialog_proc_3(HWND dialog, UINT message, WPARAM w_param, LPARAM l_param){ static device_context_t *device = NULL; char tmp[MAX_PATH]; switch(message) { case WM_INITDIALOG: device = (device_context_t *)l_param; sprintf(tmp, "%s\n" "Vendor ID:\t\t 0x%04X\n\n" "Product ID:\t\t 0x%04X\n\n" "Device description:\t %s\n\n" "Manufacturer:\t\t %s\n\n", info_text_1, device->vid, device->pid, device->description, device->manufacturer); SetWindowText(GetDlgItem(dialog, ID_INFO_TEXT), tmp); return TRUE; case WM_COMMAND: switch(LOWORD(w_param)) { case ID_BUTTON_NEXT: case IDCANCEL: EndDialog(dialog, 0); return TRUE ; } } return FALSE;}static void device_list_init(HWND list){ LVCOLUMN lvc; ListView_SetExtendedListViewStyle(list, LVS_EX_FULLROWSELECT); memset(&lvc, 0, sizeof(lvc)); lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; lvc.fmt = LVCFMT_LEFT; lvc.cx = 70; lvc.iSubItem = 0; lvc.pszText = "Vendor ID"; ListView_InsertColumn(list, 1, &lvc); lvc.cx = 70; lvc.iSubItem = 1; lvc.pszText = "Product ID"; ListView_InsertColumn(list, 2, &lvc); lvc.cx = 250; lvc.iSubItem = 2; lvc.pszText = "Description"; ListView_InsertColumn(list, 3, &lvc); }static void device_list_refresh(HWND list){ HDEVINFO dev_info; SP_DEVINFO_DATA dev_info_data; int dev_index = 0; device_context_t *device; char tmp[MAX_PATH]; device_list_clean(list); dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); dev_index = 0; dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); if(dev_info == INVALID_HANDLE_VALUE) { return; } while(SetupDiEnumDeviceInfo(dev_info, dev_index, &dev_info_data)) { if(usb_registry_match(dev_info, &dev_info_data)) { device = (device_context_t *) malloc(sizeof(device_context_t)); memset(device, 0, sizeof(*device)); usb_registry_get_property(SPDRP_HARDWAREID, dev_info, &dev_info_data, tmp, sizeof(tmp) - 1); sscanf(tmp + sizeof("USB\\VID_") - 1, "%04x", &device->vid); sscanf(tmp + sizeof("USB\\VID_XXXX&PID_") - 1, "%04x", &device->pid); usb_registry_get_property(SPDRP_DEVICEDESC, dev_info, &dev_info_data, tmp, sizeof(tmp) - 1); strcpy(device->description, tmp); usb_registry_get_property(SPDRP_MFG, dev_info, &dev_info_data, tmp, sizeof(tmp) - 1); strcpy(device->manufacturer, tmp); device_list_add(list, device); } dev_index++; } SetupDiDestroyDeviceInfoList(dev_info);}static void device_list_add(HWND list, device_context_t *device){ LVITEM item; char vid[32]; char pid[32]; memset(&item, 0, sizeof(item)); memset(vid, 0, sizeof(vid)); memset(pid, 0, sizeof(pid)); sprintf(vid, "0x%04X", device->vid); sprintf(pid, "0x%04X", device->pid); item.mask = LVIF_TEXT | LVIF_PARAM; item.lParam = (LPARAM)device; ListView_InsertItem(list, &item); ListView_SetItemText(list, 0, 0, vid); ListView_SetItemText(list, 0, 1, pid); ListView_SetItemText(list, 0, 2, device->description);}static void device_list_clean(HWND list){ LVITEM item; memset(&item, 0, sizeof(LVITEM)); while(ListView_GetItem(list, &item)) { if(item.lParam) free((void *)item.lParam); ListView_DeleteItem(list, 0); memset(&item, 0, sizeof(LVITEM)); }}static int save_file(HWND dialog, device_context_t *device){ OPENFILENAME open_file; char inf_name[MAX_PATH]; char inf_path[MAX_PATH]; char cat_name[MAX_PATH]; char cat_path[MAX_PATH]; char cat_name_x64[MAX_PATH]; char cat_path_x64[MAX_PATH]; char error[MAX_PATH]; FILE *file; memset(&open_file, 0, sizeof(open_file)); strcpy(inf_path, "your_file.inf"); open_file.lStructSize = sizeof(OPENFILENAME); open_file.hwndOwner = dialog; open_file.lpstrFile = inf_path; open_file.nMaxFile = sizeof(inf_path); open_file.lpstrFilter = "*.inf\0*.inf\0"; open_file.nFilterIndex = 1; open_file.lpstrFileTitle = inf_name; open_file.nMaxFileTitle = sizeof(inf_name); open_file.lpstrInitialDir = NULL; open_file.Flags = OFN_PATHMUSTEXIST; open_file.lpstrDefExt = "inf"; if(GetSaveFileName(&open_file)) { strcpy(cat_path, inf_path); strcpy(cat_name, inf_name); strcpy(cat_path_x64, inf_path); strcpy(cat_name_x64, inf_name); strcpy(strstr(cat_path, ".inf"), ".cat"); strcpy(strstr(cat_name, ".inf"), ".cat"); strcpy(strstr(cat_path_x64, ".inf"), "_x64.cat"); strcpy(strstr(cat_name_x64, ".inf"), "_x64.cat"); file = fopen(inf_path, "w"); if(file) { fprintf(file, "%s", inf_header); fprintf(file, "CatalogFile = %s\n", cat_name); fprintf(file, "CatalogFile.NT = %s\n", cat_name); fprintf(file, "CatalogFile.NTAMD64 = %s\n\n", cat_name_x64); fprintf(file, "%s", inf_body); fprintf(file, "[Devices]\n"); fprintf(file, "\"%s\"=LIBUSB_DEV, USB\\VID_%04x&PID_%04x\n\n", device->description, device->vid, device->pid); fprintf(file, "[Devices.NT]\n"); fprintf(file, "\"%s\"=LIBUSB_DEV, USB\\VID_%04x&PID_%04x\n\n", device->description, device->vid, device->pid); fprintf(file, "[Devices.NTAMD64]\n"); fprintf(file, "\"%s\"=LIBUSB_DEV, USB\\VID_%04x&PID_%04x\n\n", device->description, device->vid, device->pid); fprintf(file, strings_header); fprintf(file, "manufacturer = \"%s\"\n", device->manufacturer); fclose(file); } else { sprintf(error, "Error: unable to open file: %s", inf_name); MessageBox(dialog, error, "Error", MB_OK | MB_APPLMODAL | MB_ICONWARNING); } file = fopen(cat_path, "w"); if(file) { fprintf(file, "%s", cat_file_content); fclose(file); } else { sprintf(error, "Error: unable to open file: %s", cat_name); MessageBox(dialog, error, "Error", MB_OK | MB_APPLMODAL | MB_ICONWARNING); } file = fopen(cat_path_x64, "w"); if(file) { fprintf(file, "%s", cat_file_content); fclose(file); } else { sprintf(error, "Error: unable to open file: %s", cat_name_x64); MessageBox(dialog, error, "Error", MB_OK | MB_APPLMODAL | MB_ICONWARNING); } return TRUE; } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -