User DLL doesn't work when using CButton

n559br's Avatar, Join Date: Dec 2007
Newbie Member
I am trying to make a user DLL which includes the MFC derived class CButton (or really any MFC class). If I leave the CButton class out the dll runs great. As soon as I include the CButton member the executable causes a trap as soon as DoModal is called. Any ideas?


#define DLLAPI _declspec(dllexport)

class MyClass : CDialog
{
DECLARE_DYNAMIC(MyClass)
public:
DLLAPI MyClass();
DLLAPI DoModal();

CButton aBtn;
}
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You probably need to see what is there in DoModal() - If you have overridden it or if you have something in the class which you have missed to initialize.
n559br's Avatar, Join Date: Dec 2007
Newbie Member
I don't think it's in DoModal. The program will show the dialog, but after returning and making a call to SetResourceHandle I get e run time error that says the stack around aDlg has been corrupted. The calling program and class header are below.
Code:
#define APIDLL _declspec(dllimport)

// aDialog dialog

class CModTest2Dlg: public CDialog
{

public:
	APIDLL CModTest2Dlg(CWnd* pParent = NULL);   // standard constructor
	APIDLL int DoModal();

};

int CModTest2Dlg::DoModal()
{
	CDialog::DoModal();
	return(0);
}
void CImportClassDlg::OnBnClickedBtnTest()
{
	CModTest2Dlg aDlg;
	// TODO: Add your control notification handler code here
		HINSTANCE hClientResources = AfxGetResourceHandle();
	AfxSetResourceHandle(::GetModuleHandle("MxModSim.dll"));
	aDlg.DoModal();

	AfxSetResourceHandle(hClientResources);
}

Last edited by shabbir; 3Dec2007 at 17:39.. Reason: Code block
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Try running in the debug mode and see where the program is crashing or giving any ASSERT.