boost::任何析构函数崩溃
主exe加载dll。从 dll 调用函数返回简单的 boost::any。如果在析构函数中 FreeLibrary 应用程序崩溃后 boost::any 被删除。没关系。但我不明白为什么这段代码也会在 r2 析构函数处崩溃,在 main 中创建的 r2 和删除不需要 dll 代码。 如何在 FreeLibrary 之后保存 boost::any 。 尝试不使用外部“C” - 效果相同。
控制台代码:
int _tmain(int argc, _TCHAR* argv[])
{
any r2;
HMODULE hmod = LoadLibrary(L"dll");
typedef any (*dllfunc)(int,int,int);
dllfunc func = (dllfunc) GetProcAddress(hmod,"Export1");
{
any r = func(1,2,3);
r2 = r;
}
FreeLibrary(hmod);
return 0;
}
Dll代码:
extern "C"
{
DLL_API any Export1(int a,int b, int c)
{
return a+b+c;
}
}
编译Visual Studio 2005
Main exe loads dll. Calls function from dll returning simple boost::any. If boost::any deleted after FreeLibrary app crash at destructor. It's ok. But I can't understand why this code also crash at r2 destructor, r2 created in main and delete doesn't need dll code.
How can I save boost::any after FreeLibrary.
Tried without extern "C" - same effect.
Console code:
int _tmain(int argc, _TCHAR* argv[])
{
any r2;
HMODULE hmod = LoadLibrary(L"dll");
typedef any (*dllfunc)(int,int,int);
dllfunc func = (dllfunc) GetProcAddress(hmod,"Export1");
{
any r = func(1,2,3);
r2 = r;
}
FreeLibrary(hmod);
return 0;
}
Dll code:
extern "C"
{
DLL_API any Export1(int a,int b, int c)
{
return a+b+c;
}
}
compiler Visual Studio 2005
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于
any
实际是什么。例如,它可能是某个带有析构函数的对象的shared_ptr
,而析构函数代码驻留在 DLL 中。然后,any
的所有实例都应在 DLL 卸载之前销毁。This depends on what actually
any
is. For instance it might be ashared_ptr
to some object with destructor, whereas the destructor code resides in the DLL. Then all the instances ofany
should be destroyed prior to DLL unload.我遇到了同样的问题,内存管理器不处理空指针。
I had the same problem with a memory manager not handling null pointers.