Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

AttachControlSite not working

I have attached CWGraph control into my dialog, created member variable pointer with the same class and then try to get the object with AttachControlSite(this, IDC_GRAPH1). Since I could not get the handle with:

CNiGraph graph;
graph.AttachControlSite(this, IDC_GRAPH1); // this resulted in graph being NULL

I tried this:

CNiGraph* p_graph;

p_graph = (CNiGraph*)GetDlgItem(IDC_GRAPH1); // CWnd is NULL, but I'm getting NI::CNiControl with this call and CWnd is part of it

p_graph->AttachControlSite(this, IDC_GRAPH1); // This doesn't change anything


This call fails naturally since CWnd is not initialized:

m_pCalGraph->PlotXY(fr, (dPwrLvl*-1) - 10);

"Unhandled exception at 0x78244515 (mfc80d.dll) in foo.exe: 0xC0000005: Access violation reading location 0x0000009c."

In afxstate.cpp where pNewState in NULL.

    if (AfxGetAmbientActCtx() &&
        pNewState->m_hActCtx != INVALID_HANDLE_VALUE)



0 Kudos
Message 1 of 6
(6,880 Views)
Hi Sami71,

Please see if you are having the same issue as discussed in this thread:
http://forums.ni.com/ni/board/message?board.id=231&message.id=3138&requireLogin=False

What version of Measurement Studio are you using?


Gavin Fox
Systems Software
National Instruments
0 Kudos
Message 2 of 6
(6,861 Views)
8.1.0.256

I have been able to create the control with

    m_CalGraph.Create("", WS_VISIBLE, wr, this, IDC_CWGRAPH2, NULL, false);

but it would be nice if I could just get the handle for it from the existing graph from dialog. This doesn't seem to work either:

    DDX_Control(pDX,
IDC_CWGRAPH2, m_CalGraph);

I did make the mistake of using the Visual Studio wrapper instead of using the Measurement Studio toolbar.
0 Kudos
Message 3 of 6
(6,851 Views)
Seems like the dynamic Create() gives me another problem, it seems to embed the "Evalution Version" on distributed EXE's Graph. Now I need to figure out how to statically create the control in Dialog editor, which BTW does not give me the option to "Add Variable..."
0 Kudos
Message 4 of 6
(6,763 Views)
I think I got it solved.
0 Kudos
Message 5 of 6
(6,755 Views)
Hi Sami71,

It sounds like you already got the issue taken care of, but just in case, check out the
How Do I Create Controls Dynamically in Microsoft Visual C++ When Using MFC without the Demo Mode Me... KnowledgeBase.

Hope this helps!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 6 of 6
(6,743 Views)