win平台下增加DllMain入口函数并添加模块路径全局变量

This commit is contained in:
gb 2022-05-27 09:24:28 +08:00
parent dbd490b67c
commit ae50bc7d72
5 changed files with 55 additions and 3 deletions

View File

@ -922,6 +922,8 @@ int hg_scanner::setting_help(void* data)
printf("helpfile = %s\r\n",helpfile.c_str());
#ifdef WIN32
com = "";
helpfile.insert(0, g_module_path);
FILE* src = fopen(helpfile.c_str(), "rb");
if (src)
fclose(src);

View File

@ -22,6 +22,7 @@
#include "PaperSize.h"
#ifdef WIN32
extern std::string g_module_path; // Ending with '\\'
#else
#include <unistd.h>
#endif
@ -373,6 +374,6 @@ public:
#else
static const std::string helpfile_ ="/opt/apps/scanner-driver-huagao/doc/HuaGoScan_scanSettings_Help_manual.pdf";//帮助文档路径
#endif
#else
static const std::string helpfile_ ="";
#elif defined(WIN32)
static const std::string helpfile_ = "docs\\help_setting.pdf";
#endif

View File

@ -99,3 +99,28 @@ extern "C"
return hg_scanner_mgr::instance()->hg_scanner_control(h, code, data, len);
}
}
#ifdef WIN32
std::string g_module_path = "";
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
if (g_module_path.empty())
{
char path[MAX_PATH] = { 0 };
GetModuleFileNameA(inst, path, _countof(path) - 1);
if (strrchr(path, '\\'))
{
strrchr(path, '\\')[1] = 0;
g_module_path = path;
}
}
}
return TRUE;
}
#endif

View File

@ -2696,3 +2696,26 @@ extern "C" { // avoid compiler exporting name in C++ style !!!
}
#ifdef WIN32
std::string g_module_path = "";
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
if (g_module_path.empty())
{
char path[MAX_PATH] = { 0 };
GetModuleFileNameA(inst, path, _countof(path) - 1);
if (strrchr(path, '\\'))
{
strrchr(path, '\\')[1] = 0;
g_module_path = path;
}
}
}
return TRUE;
}
#endif

View File

@ -9,6 +9,7 @@
#include <stdio.h>
#ifdef WIN32
#define bzero(b, s) memset(b, 0, s)
extern std::string g_module_path; // Ending with '\\'
#else
#include <iconv.h>
#endif