我正在尝试从 c++ dll 中使用 pantheios 日志记录框架。我已经成功构建了 dll,它通过我的测试应用程序(C++ MFC 应用程序)执行。
我使用了隐式链接,包括:
#include <pantheios/implicit_link/core.h>
#include <pantheios/implicit_link/fe.simple.h>
#include <pantheios/implicit_link/be.console.h>
我的 DllMain 使用以下调用初始化 pantheios:
extern "C" const char PANTHEIOS_FE_PROCESS_IDENTITY[] = "FinishingLineController";
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
int panres = pantheios::pantheios_init();
if(panres < 0)
{
fprintf(stderr, "Failed to initialise the Pantheios libraries: %s\n",
pantheios::pantheios_getInitErrorString(panres));
return FALSE;
}
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
pantheios::pantheios_uninit();
break;
}
return TRUE;
}
当我执行下面的代码时,我得到一个
Microsoft C++ 异常:内存位置 0x0013da84 处的 STLsoft::winSTL_project::windows_exception
pantheios::log_DEBUG("Test logging");
我曾尝试使用显式链接来代替,但没有任何结果。
最佳答案
AFAICT,您的代码看起来完整且正确,但很难知道您是如何使用它的,以及您从何处以及何时获得异常。我认为您应该提供更多信息。
有一件事我要说:你可能想使用 Pantheios的内部日志记录“bailout”功能 - 我想是日志的日志。所以,你的
fprintf(stderr, "Failed to initialise the Pantheios libraries: %s\n",
pantheios::pantheios_getInitErrorString(panres));
最好写成
pantheios::util::onBailOut(pantheios::emergency,
"Failed to initialise the Pantheios libraries",
PANTHEIOS_FE_PROCESS_IDENTITY,
pantheios::getInitErrorString(panres));
这样你的日志初始化失败本身就会被记录下来。
关于c++ - 从 dll 使用 Pantheios 日志记录框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1460185/