DllMain加载其他DLL造成的死锁问题及其解决办法
2013-11-21 10:41
274 查看
使用VS 2008新建一个MFC ActiveX工程,因为在工程里要用到GDI+。我习惯把初始化GDI+库的代码放在应用程序类的InitInstance函数,对应的销毁代码放在ExitInstance函数。具体如下:
先在应用程序类里定义一个数据成员:
[cpp] view plaincopy
ULONG_PTR m_gdiplusToken;
然后添加初始化GDI+库的代码和对应的销毁代码:
[cpp] view plaincopy
BOOL CImagePreviewXApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
// TODO: Add your own module initialization code here.
// Initialize GDI+ 的初始化代码,建议放在//InitInstance函数
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
}
return bInit;
}
// CImagePreviewXApp::ExitInstance - DLL termination
int CImagePreviewXApp::ExitInstance()
{
// TODO: Add your own module termination code here.
GdiplusShutdown(m_gdiplusToken);
return COleControlModule::ExitInstance();
}
结果在编译时老是出现一个问题,就是编译时输出窗口:
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Registering output...
到了这里,VS 2008就像停滞一样,半天不反应,直到我取消生成。我以为是VS 2008的bug,因为我用VS 2010编译这个工程并无这个现象(这个实在有点令人奇怪!)。到论坛一问,蒋晟大侠告知:在DllMain的封装函数InitInstance中有加载其他DLL造成了死锁。
怎么解决这个问题呢?一种方法是写两个接口函数分别实现初始化GDI+库和对应的销毁功能。我懒得写两个接口函数,干脆把这个工作放在ActiveX控件类(派生自COleControl的那个类)的构造函数和析构函数里。
from:/article/2582421.html
先在应用程序类里定义一个数据成员:
[cpp] view plaincopy
ULONG_PTR m_gdiplusToken;
然后添加初始化GDI+库的代码和对应的销毁代码:
[cpp] view plaincopy
BOOL CImagePreviewXApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
// TODO: Add your own module initialization code here.
// Initialize GDI+ 的初始化代码,建议放在//InitInstance函数
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
}
return bInit;
}
// CImagePreviewXApp::ExitInstance - DLL termination
int CImagePreviewXApp::ExitInstance()
{
// TODO: Add your own module termination code here.
GdiplusShutdown(m_gdiplusToken);
return COleControlModule::ExitInstance();
}
结果在编译时老是出现一个问题,就是编译时输出窗口:
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Registering output...
到了这里,VS 2008就像停滞一样,半天不反应,直到我取消生成。我以为是VS 2008的bug,因为我用VS 2010编译这个工程并无这个现象(这个实在有点令人奇怪!)。到论坛一问,蒋晟大侠告知:在DllMain的封装函数InitInstance中有加载其他DLL造成了死锁。
怎么解决这个问题呢?一种方法是写两个接口函数分别实现初始化GDI+库和对应的销毁功能。我懒得写两个接口函数,干脆把这个工作放在ActiveX控件类(派生自COleControl的那个类)的构造函数和析构函数里。
from:/article/2582421.html
相关文章推荐
- DllMain加载其他DLL造成的死锁问题及其解决办法
- DllMain加载其他DLL造成的死锁问题及其解决办法
- 有关c#.net“无法加载 CSOpenGLC.dll:找不到指定的模块”的问题解决办法
- DllMain中不当操作导致死锁问题的分析--加载卸载DLL与DllMain死锁的关系
- 还是关于无法加载DLL(OCI.DLL)问题解决办法!
- C#开发中提示无法加载DLL"***.dll":找不到指定的模块(异常来自HRESULT:0x8007007E)问题的解决办法
- DllMain中不当操作导致死锁问题的分析--加载卸载DLL与DllMain死锁的关系
- 关于无法加载DLL"***.dll":找不到指定的模块(异常来自HRESULT:0x8007007E)问题的解决办法
- Rundll加载dll时出现问题 找不到指定模块解决办法
- [转载] DllMain中不当操作导致死锁问题的分析--加载卸载DLL与DllMain死锁的关系
- java中调用本地动态链接库(*.DLL)的两种方式详解和not found library、打包成jar,war包dll无法加载等等问题解决办法
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起。问题的解决方法!
- 在Win7上安装AutoCAD2007碰到的问题及其解决办法
- 学生信息管理系统---信息查询窗口无法查询到数据(问题及其解决办法)
- 当页面加载的时候就捕获其keydown事件所遇到的问题以及解决办法。
- 解决 PHP 加载 dll 模块出错的问题
- 解决客户端调用FDO动态库加载不正常造成的问题
- 跨域问题及其解决办法
- 关于Chrome浏览器加载某些CSS文件超慢或超时的奇葩问题的解决办法
- SQLServer2005数据库没有删除所有其他快照引发的问题及其解决方法