NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

assertion failure using MFC-DLL

"I've about the same problem as it's described in another post and tried to implement the proposed solution but can't get it to run. I always receive an assertion failure.
I try to fill the ComboBox in a dialog with items at runtime. (use VC++ and MFC-DLL)

the header of my dialog:


class DlgSelectECU : public CDialog
{
public:
DlgSelectECU(CWnd* pParent = NULL);
BOOL OnInitDialog();
//{{AFX_DATA(DlgSelectECU)
enum { IDD = IDD_DLGSELECTECU_DIALOG };
CComboBox m_ECUList;
CStringList m_StringList;
//}}AFX_DATA


//{{AFX_VIRTUAL(DlgSelectECU)
protected:
virtual void DoDataExchange(CDataExchange*pDX);
//}}AFX_VIRTUAL


protected:
DECLARE_MESSAGE_MAP()
};


the implementation of my dialog:

DlgSelectECU:
:DlgSelectECU(CWnd* pParent /*=NULL*/)
: CDialog(DlgSelectECU::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgSelectECU)
//}}AFX_DATA_INIT
}


BOOL DlgSelectECU::OnInitDialog()
{
POSITION pos = m_StringList.GetHeadPosition();
while (pos)
{
m_ECUList.AddString(m_StringList.GetNext(pos));
}
return true;
}


void DlgSelectECU::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgSelectECU)
DDX_Control(pDX, IDC_COMBO_ECU, m_ECUList);
//}}AFX_DATA_MAP
}


my dll function TestStand calls looks like that:

EXPORT CALLBACK SelectECU(char ECUs[1024])
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());


DlgSelectECU Dlg;


Dlg.m_StringList.AddTail("ITEM 1");


if (Dlg.DoModal() == IDOK)
{
// do something
}
}


Running the sequence file in TestStand and calling the dll function descriped above causes an assertion failure each time I try to add anything to the StringList. Why? And what am I doing wrong? Is there
a docume
ntation about how to write dlls with MFC elements for use with TestStand using other tools than LabWindows/CVI? Everything I found so far is rather crude.
Thanks!"
0 Kudos
Message 1 of 3
(3,340 Views)
Hi mbrost,

If it is a debug assertion failure you are getting, this is caused by code modules that have been built in debug configuration with ASSERT expressions that are evaluating to false. If you build in release mode, these expressions will be precompiled out and will not occur at run-time. This leads to the explanation that there must be something in your dll code module that is doing this as all TestStand components are in release configuration and do not throw debug assertion failures. One typical example of C++ array classes causing an assertion failure to occur is when you step outside of its bounds, try to add an invalid object type to the array, or remove an index that doesn't exist. The cool thing about ASSERT is that if it does result in failure du
ring a debugging session you can then single step through your code to figure out what is causing it. Therefore, you should probably try debugging the SeqEdit.exe process' use of your dll from VC++. For more information on ASSERTs visit the following MSDN document:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_ryproblems.asp

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 3
(3,340 Views)
Hi,

Sorry for the late answer but I was kept out of NI site in the last time.
The assertion failure occurs first because in DlgSelectECU::OnInitDialog() you must call the base class implementation of OnInitDialog.
Just modify this method as follows:

BOOL DlgSelectECU::OnInitDialog()
{
//This will create the dialog and control windows objects
CDialog::OnInitDialog();
POSITION pos = m_StringList.GetHeadPosition();
while (pos)
{
m_ECUList.AddString(m_StringList.GetNext(pos));
}
return true;
}

This is because the AddString method of CComboBox is calling SendMessage to the window attached to the Combo control, and the Combo control window is created in the OnInitDialog of the CDialog.

Hope this helps
Silvius
Silvius Iancu
0 Kudos
Message 3 of 3
(3,340 Views)