修复应用配置时未释放返回值的问题

This commit is contained in:
gb 2023-05-26 10:08:32 +08:00
parent e1070c186f
commit 4f62c52b49
1 changed files with 35 additions and 2 deletions

View File

@ -345,11 +345,12 @@ namespace callback
// SANE_EVENT_IMAGE_OK - void* unused, be NULL, flag - unused, be 0 // SANE_EVENT_IMAGE_OK - void* unused, be NULL, flag - unused, be 0
static HMODULE hui = NULL; static HMODULE hui = NULL;
int (*choose_scanner)(const std::vector<DEVQUEUI>& devs) = NULL; // blocked. return selected DEVQUE::id or -1 if user cancelled int (*choose_scanner)(const std::vector<DEVQUEUI>& devs) = NULL; // blocked. return selected DEVQUE::id or -1 if user cancelled
int (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配<E5898D>? char* (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配<E5898D>?
int (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, const char* devname, bool with_scan, std::function<void(ui_result)> callback) = NULL; int (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, const char* devname, bool with_scan, std::function<void(ui_result)> callback) = NULL;
int (*show_progress_ui)(HWND parent, std::function<void(ui_result)> callback, std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)>* notify) = NULL; int (*show_progress_ui)(HWND parent, std::function<void(ui_result)> callback, std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)>* notify) = NULL;
int (*show_messagebox_ui)(HWND parent, int event, void* msg, int flag) = NULL; int (*show_messagebox_ui)(HWND parent, int event, void* msg, int flag) = NULL;
int (*close_ui)(int) = NULL; int (*close_ui)(int) = NULL;
void (*twain_ui_free)(void* buf) = NULL;
static void init_ui(void) static void init_ui(void)
@ -380,6 +381,7 @@ namespace callback
GET_API(show_progress_ui); GET_API(show_progress_ui);
GET_API(show_messagebox_ui); GET_API(show_messagebox_ui);
GET_API(close_ui); GET_API(close_ui);
GET_API(twain_ui_free);
} }
} }
static void unint_ui(void) static void unint_ui(void)
@ -392,12 +394,39 @@ namespace callback
show_progress_ui = NULL; show_progress_ui = NULL;
show_messagebox_ui = NULL; show_messagebox_ui = NULL;
close_ui = NULL; close_ui = NULL;
twain_ui_free = NULL;
if (hui) if (hui)
{ {
FreeLibrary(hui); FreeLibrary(hui);
hui = NULL; hui = NULL;
} }
} }
// check thread whether has window
static BOOL WINAPI check_window(HWND hwnd, LPARAM lp)
{
LPDWORD id = (LPDWORD)lp;
if (GetWindowThreadProcessId(hwnd, NULL) == id[0])
{
id[1] = 1;
return FALSE;
}
return TRUE;
}
static bool is_thread_has_window(DWORD thread_id = -1)
{
if (thread_id == -1)
thread_id = GetCurrentThreadId();
DWORD param[] = { thread_id, 0 };
EnumWindows(check_window, (LPARAM)param);
return param[1];
}
} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -717,7 +746,11 @@ void scanner::save_config(const wchar_t* file)
void scanner::apply_config(void) void scanner::apply_config(void)
{ {
if (callback::apply_current_config) if (callback::apply_current_config)
callback::apply_current_config(local_trans::u2a(scanner_name_.c_str(), CP_UTF8).c_str(), handle_, &sane_api_); {
char* cfg = callback::apply_current_config(local_trans::u2a(scanner_name_.c_str(), CP_UTF8).c_str(), handle_, &sane_api_);
if (cfg && callback::twain_ui_free)
callback::twain_ui_free(cfg);
}
else if (cfg_) else if (cfg_)
{ {
gb::sane_config_schm* schm = cfg_->get_scheme(); gb::sane_config_schm* schm = cfg_->get_scheme();