Click here to Skip to main content
15,887,812 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Minor errors in OLE DB Pin
Prakash Nadar27-Feb-04 4:03
Prakash Nadar27-Feb-04 4:03 
GeneralRe: Minor errors in OLE DB Pin
misha_grewal27-Feb-04 4:09
misha_grewal27-Feb-04 4:09 
Generalfile date time stamps Pin
ByNar27-Feb-04 2:36
ByNar27-Feb-04 2:36 
GeneralRe: file date time stamps Pin
David Crow27-Feb-04 5:17
David Crow27-Feb-04 5:17 
GeneralGetAdaptersInfo with windows NT Pin
Aviv Halperin27-Feb-04 2:25
Aviv Halperin27-Feb-04 2:25 
GeneralGrabbing text from Window document Pin
Kashif Ali24527-Feb-04 1:47
sussKashif Ali24527-Feb-04 1:47 
GeneralRe: Grabbing text from Window document Pin
David Crow27-Feb-04 5:22
David Crow27-Feb-04 5:22 
GeneralModeless Dialog in DLL Pin
paul hoshovsky27-Feb-04 1:23
paul hoshovsky27-Feb-04 1:23 
Hello

I need working example of a Modeless Dialog in DLL using MFC and LoadLibrary.
(in this code fragment I left out error checking.)

What I have done is

in MainEXEView.cpp

void CMainEXEView::OnButton1()
{
HandleToDLL= LoadLibrary("modelessDLL.dll");
InterfaceDLLPointer = (DLLInterfaceMethod) (GetProcAddress(HandleToDLL,"CreateMyDlg"));
TheHwnd = GetDlgItem(IDC_HOLDDLL)->m_hWnd;
InterfaceDLLPointer(TheHwnd);}
}
in the DLL.cpp ( statically linked DLL)

dlldlg *dlg;
__declspec (dllexport) __stdcall CreateMyDlg(HWND pParentWnd)
{
CRect rc;

AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Need this to switch to local module state.
CWnd * Parent = CWnd::FromHandle(pParentWnd);
dlg = new dlldlg();
dlg->Create(dlldlg::IDD, Parent);
dlg->ShowWindow(SW_SHOWNORMAL);
Parent ->GetWindowRect(rc);
Parent ->ScreenToClient(&rc);
dlg->MoveWindow(rc);
return dlg->m_hWnd;
}

The dlldlg has some buttons for testing.

At this point, the DLL dialog appears correctly on the screen. The problem is not that the keyboard events fail, as reported elsewhere.

Rather, the buttons do not work and the program hangs. So....

I did the following:

BOOL CMainEXEView::PreTranslateMessage(MSG* pMsg)
{
BOOL AnyMessages;

AnyMessages=CFormView::PreTranslateMessage(pMsg);
if (!AnyMessages)
{
if (Ready)
{
if (InterfaceDLLPointer_Messages!=NULL)
AnyMessages= InterfaceDLLPointer_Messages(pMsg);
}
}
return AnyMessages;
}

where InterfaceDLLPointer_Messages was another entry point into the DLL, called HandleMessages

DLL.cpp

__declspec (dllexport) BOOL __stdcall HandleMessages(MSG *pMsg)
{
// return theApp.PreTranslateMessage( pMsg); // this did not help
// return dlg->PreTranslateMessage( pMsg); // this crashes

AFX_MANAGE_STATE(AfxGetStaticModuleState());
TRY
{
return AfxGetThread()->PreTranslateMessage(pMsg);
}
END_TRY
return FALSE;
}

The variations in this method did not help.

I can trace the flow from the main app via PreTranslateMessage into the DLL.

Clicking on any button on the modeless dialog hangs the code.

I would welcome any comments but best of all a working sample.

Thanks to everyone.



Paul
GeneralRe: Modeless Dialog in DLL Pin
Prakash Nadar27-Feb-04 4:34
Prakash Nadar27-Feb-04 4:34 
GeneralRe: Modeless Dialog in DLL Pin
paul hoshovsky2-Mar-04 1:50
paul hoshovsky2-Mar-04 1:50 
GeneralDetecting Keyboard Input in Console Application Pin
Tomaz Rotovnik27-Feb-04 1:11
Tomaz Rotovnik27-Feb-04 1:11 
GeneralRe: Detecting Keyboard Input in Console Application Pin
Selvam R27-Feb-04 1:19
professionalSelvam R27-Feb-04 1:19 
GeneralRe: Detecting Keyboard Input in Console Application Pin
catngo27-Feb-04 19:24
catngo27-Feb-04 19:24 
GeneralSorting an array with pointers Pin
hollowsoft27-Feb-04 0:52
hollowsoft27-Feb-04 0:52 
GeneralRe: Sorting an array with pointers Pin
Selvam R27-Feb-04 1:16
professionalSelvam R27-Feb-04 1:16 
GeneralRe: Sorting an array with pointers Pin
Kevin McFarlane27-Feb-04 1:17
Kevin McFarlane27-Feb-04 1:17 
GeneralRe: Sorting an array with pointers Pin
Kevin McFarlane27-Feb-04 4:46
Kevin McFarlane27-Feb-04 4:46 
GeneralRe: Sorting an array with pointers Pin
David Crow27-Feb-04 5:28
David Crow27-Feb-04 5:28 
GeneralGlyph Repositioning Pin
Member 88417927-Feb-04 0:24
Member 88417927-Feb-04 0:24 
QuestionVideo memory, why so slow? Pin
includeh1027-Feb-04 0:01
includeh1027-Feb-04 0:01 
QuestionMessageBox and font changing? Pin
Jump_Around26-Feb-04 23:57
Jump_Around26-Feb-04 23:57 
AnswerRe: MessageBox and font changing? Pin
Prakash Nadar27-Feb-04 0:11
Prakash Nadar27-Feb-04 0:11 
GeneralProblem with critical section. Pin
Prakash Nadar26-Feb-04 23:47
Prakash Nadar26-Feb-04 23:47 
GeneralRe: Problem with critical section. Pin
_Magnus_27-Feb-04 0:11
_Magnus_27-Feb-04 0:11 
GeneralRe: Problem with critical section. Pin
Prakash Nadar27-Feb-04 0:14
Prakash Nadar27-Feb-04 0:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.