CFileDialog: DoModal() == IDOK 导致外部DLL不能全部成功load,该如何处理
CFileDialog:: DoModal() == IDOK 导致外部DLL不能全部成功load
void CTestListCtrl::OnMenuClickAdd()
{
CFileDialog dlgFile(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, this, 0, TRUE);
TCHAR *pBuffer = new TCHAR[MAX_PATH*100];//最多允许个文件
dlgFile.m_ofn.lpstrFile = pBuffer;
dlgFile.m_ofn.lpstrFile[0] = NULL;
dlgFile.m_ofn.nMaxFile = 100*MAX_PATH;
dlgFile.m_ofn.lStructSize = sizeof(OPENFILENAME);
INT_PTR result = dlgFile.DoModal();
if( result == IDOK )
{
CString strFileName;
POSITION pos = dlgFile.GetStartPosition();
while (pos != NULL)
{
strFileName = dlgFile.GetNextPathName(pos);
CConvertInfo convertInfo;
convertInfo.m_strFilename = strFileName;
m_convetInfos.AddTail(convertInfo);
}
}
CTestDlg* pWnd = (CTestDlg*)this->GetParent();
pWnd->UpdateListCtrl();
delete pBuffer;
}
如果在打开的窗口中没有选择任何文件就返回, 即result != IDOK,那么如下5个DLL会被成功LOAD进来,否则,如果result == IDOK, 则只有前面3个dll会被load进来。
'Test.exe': Loaded 'E:\Current\Product\Test\Debug\imlib2.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\Debug\libImlib2-1.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\Debug\libfreetype-6.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\imlib2\loaders\png.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\libpng-3.dll', Binary was not built with debug information.
但是我的逻辑是不管选不选择文件, 5个都应该load进来. 请问有人知道是什么原因.
已经弄了两天了还是没有找到原因,如果有高手知道,并帮忙解决,一定给分.
------解决方案--------------------
应该和路径有关。
应为CFileDialog如果选择文件的话,会将操作系统的默认相对路径修改为你选择的文件所在的路径。
不知道你这些动态库在载入的时候,是否使用了绝对路径。如果是相对路径的话,就会有问题了。
------解决方案--------------------
没有看到那儿有装载动态库的代码呀,楼主是不是漏贴了?
------解决方案--------------------
CConvertInfo convertInfo;是个什么
局部变量在退出循环的时候已经被解析了,
如果不是在m_convetInfos.AddTail()函数里面做了处理 则在读到底队列的数据就是过期的无效数据
建议
CConvertInfo *convertInfo = new CConvertInfo;
convertInfo->m_strFilename = strFileName;
m_convetInfos.AddTail(convertInfo);
记得退出的时候 delete
void CTestListCtrl::OnMenuClickAdd()
{
CFileDialog dlgFile(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, this, 0, TRUE);
TCHAR *pBuffer = new TCHAR[MAX_PATH*100];//最多允许个文件
dlgFile.m_ofn.lpstrFile = pBuffer;
dlgFile.m_ofn.lpstrFile[0] = NULL;
dlgFile.m_ofn.nMaxFile = 100*MAX_PATH;
dlgFile.m_ofn.lStructSize = sizeof(OPENFILENAME);
INT_PTR result = dlgFile.DoModal();
if( result == IDOK )
{
CString strFileName;
POSITION pos = dlgFile.GetStartPosition();
while (pos != NULL)
{
strFileName = dlgFile.GetNextPathName(pos);
CConvertInfo convertInfo;
convertInfo.m_strFilename = strFileName;
m_convetInfos.AddTail(convertInfo);
}
}
CTestDlg* pWnd = (CTestDlg*)this->GetParent();
pWnd->UpdateListCtrl();
delete pBuffer;
}
如果在打开的窗口中没有选择任何文件就返回, 即result != IDOK,那么如下5个DLL会被成功LOAD进来,否则,如果result == IDOK, 则只有前面3个dll会被load进来。
'Test.exe': Loaded 'E:\Current\Product\Test\Debug\imlib2.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\Debug\libImlib2-1.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\Debug\libfreetype-6.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\imlib2\loaders\png.dll', Binary was not built with debug information.
'Test.exe': Loaded 'E:\Current\Product\Test\libpng-3.dll', Binary was not built with debug information.
但是我的逻辑是不管选不选择文件, 5个都应该load进来. 请问有人知道是什么原因.
已经弄了两天了还是没有找到原因,如果有高手知道,并帮忙解决,一定给分.
------解决方案--------------------
应该和路径有关。
应为CFileDialog如果选择文件的话,会将操作系统的默认相对路径修改为你选择的文件所在的路径。
不知道你这些动态库在载入的时候,是否使用了绝对路径。如果是相对路径的话,就会有问题了。
------解决方案--------------------
没有看到那儿有装载动态库的代码呀,楼主是不是漏贴了?
------解决方案--------------------
CConvertInfo convertInfo;是个什么
局部变量在退出循环的时候已经被解析了,
如果不是在m_convetInfos.AddTail()函数里面做了处理 则在读到底队列的数据就是过期的无效数据
建议
CConvertInfo *convertInfo = new CConvertInfo;
convertInfo->m_strFilename = strFileName;
m_convetInfos.AddTail(convertInfo);
记得退出的时候 delete