Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating measurement studio control dynamically in VC++7.0

We downloaded an example from the following site:

<http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3EFE056A4E034080020E74861&p_...>

We converted the project to VC++7.0 solution.

When we tried to create a single control it worked fine.

But when we create the second control it crashes.

void CDynamicControlDlg::OnButton1()

{

        CNiReal64Vector rt;                

        CNiMath::SineWave(rt, 60, 1.0);

       

        BSTR bstrLic = ::SysAllocStringLen(pwchUILic, sizeof (pwchUILic) / sizeof(WCHAR));

        m_graph1.Create("", WS_VISIBLE, CRect(110,20,370,200),this, 0,NULL, FALSE, bstrLic);

        m_graph1.PlotY(rt);                

        ::SysFreeString(bstrLic);              

        ::AfxMessageBox("WAIT for the crash.....");

        BSTR bstrLic1 = ::SysAllocStringLen(pwchUILic, sizeof (pwchUILic) / sizeof(WCHAR));

        m_graph2.Create("", WS_VISIBLE, CRect(200,120,350,300),this, 0,NULL, FALSE, bstrLic1);

        m_graph2.PlotY(rt);                

        ::SysFreeString(bstrLic1);              

}



0 Kudos
Message 1 of 2
(3,173 Views)

Each control needs to have a unique ID, which is what the 5th parameter in the Create method is. Try changing the code to the following

BSTR bstrLic = ::SysAllocStringLen(pwchUILic, sizeof (pwchUILic) / sizeof(WCHAR));

        m_graph1.Create("", WS_VISIBLE, CRect(110,20,370,200),this, 0,NULL, FALSE, bstrLic);

        m_graph1.PlotY(rt);                

        ::SysFreeString(bstrLic);              

        ::AfxMessageBox("WAIT for the crash.....");

        BSTR bstrLic1 = ::SysAllocStringLen(pwchUILic, sizeof (pwchUILic) / sizeof(WCHAR));

        m_graph2.Create("", WS_VISIBLE, CRect(200,120,350,300),this, 1002,NULL, FALSE, bstrLic1);

        m_graph2.PlotY(rt);                

        ::SysFreeString(bstrLic1);              


What you were doing was giving two controls the same control ID (0 in this case). MFC will assert in this case. I just chose 1002, but that value will depend on how many controls you have on your dialog and what IDs are available. So everytime you create a new control, make sure you give it an ID that is not being used by another control.

Hope this helps.

Message Edited by bilalD on 10-26-2005 09:17 AM

Bilal Durrani
NI
0 Kudos
Message 2 of 2
(3,162 Views)