#include "dialog_source_select.h" #include "ui_dialog_source_select.h" #include Dialog_Source_Select::Dialog_Source_Select(const char **manuNames, const char **sanePaths, QWidget *parent) : QDialog(parent), ui(new Ui::Dialog_Source_Select) { ui->setupUi(this); m_vSource.clear(); m_strManuName.clear(); m_dll = nullptr; memset(&m_saneApi, 0, sizeof(SANEAPI)); setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); const char **p1 = manuNames; const char **p2 = sanePaths; while (*p1 != NULL && *p2 != NULL) { std::pair pr; pr.first = *p1; pr.second = *p2; m_vSource.push_back(pr); ui->listWidget->addItem(*p1); ++p1; ++p2; } if (!m_vSource.empty()) { ui->listWidget->setCurrentRow(0); } } Dialog_Source_Select::~Dialog_Source_Select() { delete ui; } std::string Dialog_Source_Select::GetManuName() { return m_strManuName; } HGDll Dialog_Source_Select::GetDll() { return m_dll; } void Dialog_Source_Select::GetSaneAPI(SANEAPI *saneAPI) { memcpy(saneAPI, &m_saneApi, sizeof(SANEAPI)); } void Dialog_Source_Select::on_pushButton_OK_clicked() { int index = ui->listWidget->currentRow(); if (index < 0) { return; } HGDll dll = nullptr; HGResult ret = HGBase_CreateDll(m_vSource[index].second.c_str(), &dll); if (HGBASE_ERR_OK != ret) { QMessageBox::information(this, tr("tips"), tr("Load library failed")); return; } SANEAPI saneAPI; ret = FindFunctions(dll, m_vSource[index].first.c_str(), &saneAPI); if (HGBASE_ERR_OK != ret) { HGBase_DestroyDll(dll); dll = NULL; QMessageBox::information(this, tr("tips"), tr("Find function failed")); return; } m_strManuName = m_vSource[index].first; m_dll = dll; memcpy(&m_saneApi, &saneAPI, sizeof(SANEAPI)); accept(); } void Dialog_Source_Select::on_pushButton_Cancel_clicked() { reject(); } HGResult Dialog_Source_Select::FindFunctions(HGDll dll, const HGChar* saneManu, SANEAPI *saneAPI) { HGResult ret = HGBASE_ERR_OK; do { HGChar funcName[256]; sprintf(funcName, "sane_%s_init", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_init_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_exit", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_exit_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_get_devices", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_devices_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_open", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_open_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_close", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_close_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_start", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_start_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_read", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_read_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_cancel", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_cancel_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_set_io_mode", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_set_io_mode_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_strstatus", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_strstatus_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_get_parameters", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_parameters_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_get_option_descriptor", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_option_descriptor_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_control_option", saneManu); ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_control_option_api); if (HGBASE_ERR_OK != ret) break; } while (0); return ret; }