Re: How to display Cdialog-derived control in MFC extension DLL
On Oct 9, 5:12 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
wrote:
"ThirstyForKnowledge" <thirstyforknowle...@live.com> wrote in message
news:7565ab95-9a7b-4e5d-ac2e-b2bbe38912b1@d45g2000hsc.googlegroups.com...
Thanks for your input. I considered using that macro in the past, bu=
t
I did not use it in the past because I had the impression that the
AFX_MANAGE_STATE is used only in regulardll, whereas I use theMFC
extensiondll. I even read that Article ID: Q161589 of microsoft says
that that macro should not be used inMFCextensiondlls.
Yes it is only used in a regularDLL. Is yourdialogresource in the exe =
or
theDLL? Are you calling DoModal in the exe or in theDLL? IsMFClinke=
d
statically or dynamically to your exe andDLL? (It is best if they both
link dynamically to theMFCDLL.)
--
Scott McPhillips [VC++ MVP]
I finally foudn gow to do it, but to answer your questions: the dialog
is in the DLL and the DoModal is called from the DLL as well. the EXE
and the DLL both on MFC shard DLL.
It took me some time to understand that a Dialog cannot be displayed
without a parent window, so rather than calling the dll from a win32
console application (i.e., main wntry function), I created an MFC exe
project (dialog bases for our demonstrating purposes), and when I
called the dll function to dispaly the dialog, I passed the PARENT
WINDOW OF THE DIALOG IN THE EXE PROJECT. Assume that DialogInterface
is a clas WITHIN the dll that initialize the CDailog-derived class,
then I used the following code:
DialogInterface a(GetParent());
For the sake of completion here is the implementation of the DLL class
used from the exe file:
class AFX_EXT_CLASS DialogInterface : public CObject
{
public:
DialogInterface(CWnd * pWnd);
MyDialog * DLG;
virtual ~DialogInterface();
};
DialogInterface::~DialogInterface()
{
delete DLG;
}
DialogInterface::DialogInterface(CWnd *pWnd)
{
DLG=new MyDialog(pWnd);
DLG->DoModal();
}
However, I'm not really done with what I initially wanted to find
out. This whole journey of finding "How to display Cdialog-derived
control in MFC extension DLL" is part of a so-called master plan to
display a CDialog-derived control from and XLL. To accomplish that, I
used the idea that I can invoke a command from Excel menu item to call
a function which will use our DialogInterface above and pass its
constructor DialogInterface(CWnd *pWnd) Excel's HWND handle (casted to
CWnd). I use the xlGetHwnd function to obtain the Excel handle. I
know that the concept of just getting the parent window is right, but
for some reason I get the same error message I described above:
It is a Debug Assertion type of
error specifying line 22 in afxwin1.inl
Pleasse note that line 22 in afxwin1.inl is the middle line of the
following function:
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL); //this is the
line where
code fails
return afxCurrentResourceHandle; }
Any idea what do I do wrong if I do use Excel parent's window ?
Thanks for your help