Re: Why does AfxGetMainWnd returns nulls?
Hello All,
Its the main exe that is poping up the parent window, whose handle I am
interested in. The child window will be called from my dll. The window is
already created and i just need to retrieve its handle.
Can someone point out on how to use m_hWnd?
As per Ajay's question :
I have been using MFC regular dll and not the extension dll. can you let me
know how to use macro AFX_MANAGE_STATE (w/getappmodule) to make it work?
As per below comments
/*
If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
*/
AFX_MANAGE_STATE needs to be used with exported functions .
Thanks
-Megha
"Tom Serface" wrote:
If the DLL is the one popping up the dialog then knowing the main window
isn't going to help you any. You need to determine who is popping up the
window. As Ajay mentioned, you will get NULL from the call if the DLL
doesn't know about the main window.
When are you making the call? Could it be happening before the mainwnd is
created?
Tom
"MegK123" <MegK123@discussions.microsoft.com> wrote in message
news:7271AA19-D5F6-4653-AE02-78B5209AC9A1@microsoft.com...
Hello all
I am new to MFC. I have a MFC shared dll, which will be intregarted into
another application. To give details abt the dll, it creates an widget
(having grid format). When I call this MFC dll from the exe, it will
generate
an object for me. Now prior to creating the object, I have a window that
pops
asking few info (like name,type,etc). I want to retrieve the handle to
this
window. I have the create button on this window, within whose code I do
the
following
IINT32 testClass::onCreate(...)
{
typedef long int jint;
CWnd* pWnd = AfxGetMainWnd();
jint hndl = (jint)pWnd->GetSafeHwnd();
}
But, I always receieve an null from AfxGetMainWnd(). and 0 from get
safehwnd(). I do not know exactly how to associate the CWnd to my class
"testClass".
Any help ?
Thanks in advance
-Megha