-
October 9th, 2010, 08:04 AM
#1
Invoking a dialog from MFC dll.
I have coded a function like below hoping that it will show a dialog on a key press. but for some reasons it is not showing up. This code is written inside a MFC Dll. Can you help me in pointing out the problem?
The installhook is called from a mfc dialog. Also, when i give SetParent as foreground window it ends up in an assertion failure.
Code:
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,
LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetModuleState());
AfxSetResourceHandle(AfxGetInstanceHandle());
char ch;
if (HC_ACTION==nCode)
{
if ((wParam==VK_SPACE)||(wParam==VK_RETURN)||(wParam>=0x2f ) &&(wParam<=0x100))
{
/
// HWND hWnd = GetForegroundWindow();
//dlg.SetParent(CWnd::FromHandle(hWnd));
CMfcDialog dlg;
dlg.SetParent(CWnd::FromHandle(hWnd));
dlg.DoModal();
}
}
LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );
return RetVal;
}
extern "C" void __declspec(dllexport) installhook()
{
hkb=SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KeyboardProc,AfxGetInstanceHandle(),0);
}
-
October 9th, 2010, 08:55 AM
#2
Re: Invoking a dialog from MFC dll.
Originally Posted by reachb4
Code:
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,
LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetModuleState());
AfxSetResourceHandle(AfxGetInstanceHandle());
...
CMfcDialog dlg;
dlg.SetParent(CWnd::FromHandle(hWnd));
dlg.DoModal();
...
return RetVal;
}
1. Well, you cannot SetParent for the CMfcDialog dlg; because this dlg is not a window yet!
You should instead set a parent from within CMfcDialog::OnInitDialog method and pass parent handle as a parameter or member variable of CMfcDialog class.
2. You are calling
Code:
AFX_MANAGE_STATE(AfxGetModuleState());
from within LRESULT CALLBACK KeyboardProc(...). Is this pocedure in a MFC Regular dll?
Last edited by VictorN; October 9th, 2010 at 11:52 AM.
Victor Nijegorodov
-
October 9th, 2010, 11:38 AM
#3
Re: Invoking a dialog from MFC dll.
Thank you so much for your help.
I first tried normal win32 dll and secondly the MFC Dll. Neither proved a success.
-
October 9th, 2010, 11:43 AM
#4
Re: Invoking a dialog from MFC dll.
Originally Posted by reachb4
Thank you so much for your help.
I first tried normal win32 dll and secondly the MFC Dll. Neither proved a success.
You haven't answer my question:
Originally Posted by VictorN
...
2. You are calling
Code:
AFX_MANAGE_STATE(AfxGetModuleState());
from within LRESULT CALLBACK KeyboardProc(...). Is this pocedure in a MFC Regular dll?
Otherwise it is not clear why you are calling AFX_MANAGE_STATE(AfxGetModuleState()) there...
Victor Nijegorodov
-
October 9th, 2010, 11:49 AM
#5
Re: Invoking a dialog from MFC dll.
Sorry,
Yes it is in a MFC Regular Dll(MFC Shared).
Thanks,
Joe.
-
October 9th, 2010, 11:54 AM
#6
Re: Invoking a dialog from MFC dll.
Well, did you try to debug it? What does
Code:
AfxSetResourceHandle(AfxGetInstanceHandle());
return? Is it the dll instance where your CMfcDialog is defined?
Last edited by VictorN; October 9th, 2010 at 12:00 PM.
Victor Nijegorodov
-
October 9th, 2010, 11:58 AM
#7
Re: Invoking a dialog from MFC dll.
Nope, lpszcurrentname is the name of the Dialog application i created. Why is it so??
Thanks and Regards,
John.
-
October 9th, 2010, 12:02 PM
#8
Re: Invoking a dialog from MFC dll.
Originally Posted by reachb4
Nope, lpszcurrentname is the name of the Dialog application i created. Why is it so??
Ask MSDN about it!
Victor Nijegorodov
-
October 9th, 2010, 12:10 PM
#9
Re: Invoking a dialog from MFC dll.
Sure.. Thank you for your help so far.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|