从DLL打开时,CFileDialog无法工作 [英] CFileDialog could not work when open from DLL

查看:106
本文介绍了从DLL打开时,CFileDialog无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经从基于MFC对话框的项目中生成了一个DLL,并将此DLL加载到了另一个基于MFC对话框的项目中.

它可以从DLL加载对话框.但是,当我需要从对话框中打开一个新文件时,该程序将 hang 存在.我正在使用文件对话框和辅助线程来运行打开按钮的功能.

在按钮中:

Hi,

I''ve generated a DLL from a MFC dialog-based project and loaded this DLL onto another MFC dialog-based project.

it can load the dialog from the DLL. But when i need to open a new file from the dialog, the program will just hang there. I am using a File Dialog and a worker thread to run the function of the open button.

In the button:

// Delete previous items
this->UpdateData();
RunThread();
this->UpdateData(FALSE);



在工作线程中:



In the worker thread:

CFileDialog FileDlg(TRUE, ".txt", NULL, OFN_NOCHANGEDIR, strFilter);

if( FileDlg.DoModal() == IDOK )
{	
    // Open the file
}





HINSTANCE m_hViewDll;

// In 2nd Project.cpp (OnClickedCreateData)

typedef CRuntimeClass * (*GETDLLVIEW)();

AfxEnableControlContainer();

m_hViewDll = AfxLoadLibrary(".\\ProjectA.dll");
if (!m_hViewDll)
{
      AfxMessageBox("Error: Cannot find component \"ProjectA.dll\"");
      return FALSE;
}

GETDLLVIEW GetView = (GETDLLVIEW) GetProcAddress(m_hViewDll,
       "RunMainframe");
ASSERT (GetView != NULL);

// In Exit Button

if (m_hViewDll)
{
    AfxFreeLibrary(m_hViewDll);
    m_hViewDll = NULL;
}

// In ProjectA.h

class __declspec( dllexport ) CProjectAApp;
extern "C" __declspec( dllexport ) CProjectAApp* RunMainframe();
class __declspec( dllexport ) CProjectADlg;

// In ProjectA.cpp

CProjectAApp* RunMainframe()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState()) ;
	CProjectAApp* myapp=new CProjectAApp();
	myapp->InitInstance();
	myapp->Run();
	return myapp;
}



我怎么解决这个问题?如果有人可以向我解释为什么会发生这种情况,以便我可以从中学习,那就太好了.

感谢您的帮助.



How can i solve this problem? and it would be great if someone can explain to me why this happpen so that I can learn from it.

Thank you for helping.

推荐答案

您的信息很少.

我的建议是您阅读这些文章并听从他们的建议.

http://adilevin.wordpress.com/2009/06/29/user -interface-threads-in-mfc/ [ http://www.tek-tips.com/faqs.cfm?fid=5162 [ ^ ]

使用用户界面线程 [
Your information is scant.

My suggestion is you read these articles and follow their advice.

http://adilevin.wordpress.com/2009/06/29/user-interface-threads-in-mfc/[^]

http://www.tek-tips.com/faqs.cfm?fid=5162[^]

Using User-Interface Threads[^]


这篇关于从DLL打开时,CFileDialog无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆