Ask for help ___the errors in my projects to show modless dialog in dll [modified]
-
my function in dll: extern "C" _declspec(dllexport) CDialog * ShowDllDlg(HWND hWnd) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllDlg * m_pDlg =new CDllDlg(); m_pDlg->Create(IDD_DLG_DllDLG, CWnd::FromHandle(hWnd)); m_pDlg->ShowWindow(SW_SHOW); return m_pDlg; } Another function to call dll function in my test project: void CTestDlg::OnBnClickedButtonDlltest() { HWND myhWnd = this->m_hWnd; typedef CDialog * (_stdcall *Connect)(HWND hWnd); HINSTANCE hinstDLL=NULL; hinstDLL = ::LoadLibrary("AntiSubmarine.dll"); if (hinstDLL) { Connect Proc; Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg"); if (Proc!=(Connect)NULL) { m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg; //if only "Proc(myhWnd)", also the same error; } FreeLibrary(hinstDLL); } else { AfxMessageBox("Not found dll !"); } return; } when run the dll, error comes out.
modified on Wednesday, August 19, 2009 8:47 AM
-
my function in dll: extern "C" _declspec(dllexport) CDialog * ShowDllDlg(HWND hWnd) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllDlg * m_pDlg =new CDllDlg(); m_pDlg->Create(IDD_DLG_DllDLG, CWnd::FromHandle(hWnd)); m_pDlg->ShowWindow(SW_SHOW); return m_pDlg; } Another function to call dll function in my test project: void CTestDlg::OnBnClickedButtonDlltest() { HWND myhWnd = this->m_hWnd; typedef CDialog * (_stdcall *Connect)(HWND hWnd); HINSTANCE hinstDLL=NULL; hinstDLL = ::LoadLibrary("AntiSubmarine.dll"); if (hinstDLL) { Connect Proc; Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg"); if (Proc!=(Connect)NULL) { m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg; //if only "Proc(myhWnd)", also the same error; } FreeLibrary(hinstDLL); } else { AfxMessageBox("Not found dll !"); } return; } when run the dll, error comes out.
modified on Wednesday, August 19, 2009 8:47 AM
-
because you free the library after creating a modless dialog, so the error happened.
it's my pleasure to make friend with you.
First, thank you very much for your help. You said "free the library after creating a modless dialog". Beacuse I do not understand the dll, and for some resons, i have to use it with modless dialog. So, could you help me to edit the codes, and make the program run freely. Finally, thanks. it's my pleasure to make friend with you.
-
my function in dll: extern "C" _declspec(dllexport) CDialog * ShowDllDlg(HWND hWnd) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllDlg * m_pDlg =new CDllDlg(); m_pDlg->Create(IDD_DLG_DllDLG, CWnd::FromHandle(hWnd)); m_pDlg->ShowWindow(SW_SHOW); return m_pDlg; } Another function to call dll function in my test project: void CTestDlg::OnBnClickedButtonDlltest() { HWND myhWnd = this->m_hWnd; typedef CDialog * (_stdcall *Connect)(HWND hWnd); HINSTANCE hinstDLL=NULL; hinstDLL = ::LoadLibrary("AntiSubmarine.dll"); if (hinstDLL) { Connect Proc; Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg"); if (Proc!=(Connect)NULL) { m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg; //if only "Proc(myhWnd)", also the same error; } FreeLibrary(hinstDLL); } else { AfxMessageBox("Not found dll !"); } return; } when run the dll, error comes out.
modified on Wednesday, August 19, 2009 8:47 AM
void CTestDlg::OnBnClickedButtonDlltest()
{
HWND myhWnd = this->m_hWnd;typedef CDialog * (_stdcall *Connect)(HWND hWnd);
HINSTANCE hinstDLL=NULL;
hinstDLL = ::LoadLibrary("AntiSubmarine.dll");
if (hinstDLL) {
Connect Proc;
Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg");
if (Proc!=(Connect)NULL) {
m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg;
//if only "Proc(myhWnd)", also the same error;
}
//FreeLibrary(hinstDLL);
}
else {
AfxMessageBox("Not found dll !");
}
return;
}if you create a modless dialog, don't free the library which include the dialog resource until you destroy the dialog, because that modless dialog is not block like mod dialog. :)
it's my pleasure to make friend with you.
-
void CTestDlg::OnBnClickedButtonDlltest()
{
HWND myhWnd = this->m_hWnd;typedef CDialog * (_stdcall *Connect)(HWND hWnd);
HINSTANCE hinstDLL=NULL;
hinstDLL = ::LoadLibrary("AntiSubmarine.dll");
if (hinstDLL) {
Connect Proc;
Proc = (Connect)GetProcAddress(hinstDLL,"ShowDllDlg");
if (Proc!=(Connect)NULL) {
m_pdlg = (CDialog *)Proc(myhWnd);//in *.h file defines CDialog * m_pdlg;
//if only "Proc(myhWnd)", also the same error;
}
//FreeLibrary(hinstDLL);
}
else {
AfxMessageBox("Not found dll !");
}
return;
}if you create a modless dialog, don't free the library which include the dialog resource until you destroy the dialog, because that modless dialog is not block like mod dialog. :)
it's my pleasure to make friend with you.
Thank you very much for your answers. I'll try it again. if there is any error, could you help me again? May I have your Emaill for contact in the future? my Emaill: hailuolan@yahoo.com.cn :) it's my pleasure to make friend with you.