#include "dialog_source_select.h" #include "ui_dialog_source_select.h" #include #include "base/HGUtility.h" Dialog_Source_Select::Dialog_Source_Select(const std::vector > &source, QWidget *parent) : QDialog(parent), ui(new Ui::Dialog_Source_Select) { ui->setupUi(this); m_vSource = source; m_strManuName.clear(); m_dll = nullptr; memset(&m_saneApi, 0, sizeof(SANEAPI)); setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); for (int i = 0; i < m_vSource.size(); ++i) { ui->listWidget->addItem(m_vSource[i].first.c_str()); } 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; } HGChar fileName[260]; HGBase_GetFileName(m_vSource[index].second.c_str(), fileName, 260); HGDll dll = nullptr; HGResult ret = HGBase_CreateDll(fileName, &dll); if (HGBASE_ERR_OK != ret) { 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; }