Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C++
// Delete previous items
this->UpdateData();
RunThread();
this->UpdateData(FALSE);


In the worker thread:
C++
CFileDialog FileDlg(TRUE, ".txt", NULL, OFN_NOCHANGEDIR, strFilter);

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


C++
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.
Posted
Updated 29-Apr-12 20:39pm
v8
Comments
Richard MacCutchan 25-Apr-12 5:19am    
I don't have the answer but it strikes me you have too many dialogs.
Code-o-mat 25-Apr-12 8:15am    
I doubt anyone will be able to tell you why your application hands from onyl that much information, however, bringing up dialogs from secondary threads in a GUI application is usually a BAD IDEA. You should rather try to bring up the file open dialog from the GUI thread of the application that loaded your DLL and probably pass the information gathered this way to the thread afterwards for processing.
Sergey Alexandrovich Kryukov 29-Apr-12 23:08pm    
Weird idea; and you are right.
--SA
JackDingler 25-Apr-12 11:50am    
Right. Don't launch dialogs from background threads.
skfoo1 26-Apr-12 22:03pm    
Whats the reason for not launching dialogs from secondary threads?

1 solution

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[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 30-Apr-12 19:19pm    
Useful information, could be educating to OP.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900