07-06-2009 10:30 AM
Hi,
I would like to create a temporary CNiGraph object, plot some data, and render it to an image. I am able to create the object dynamically (I think) but I get a runtime error when trying to plot data (using ChartY) on the graph.
The error is in the function AfxGetAmbientActCtx.
My code for control creation looks like:
CNiGraph niGraph;
CRect rect(CPoint(0, 0), m_Size); // the size of the graph
CDC *pDC = pWnd->GetDC();
BSTR bstrLic = ::SysAllocStringLen(/* stuff to generate the license */);
niGraph.CreateControl("CWGraph", "", WS_VISIBLE, rect, pWnd,
m_staticControlID++, NULL, FALSE, bstrLic);
//use the static control ID to ensure unique IDs
::SysFreeString(bstrLic);
ChartPreviewData(niGraph, pList, settings);
// ... some untested code to render to an image follows
pWnd is a CPropertySheet (which is a valid window, but I am using as a dummy to temporarily hold the graph). ChartPreviewData does this...
void CXyzClass::ChartPreviewData(
CNiGraph &graph, ... some other arguments....)
{
// some code to get the data ready to put in the NI vector
CNiReal64Vector niVector(numPoints, pBuffer);
graph.SetChartLength(numPoints);
// Chart data and adjust delta X to reflect sampling frequency used
CNiPlot plot = graph.Plots.Add();
plot.MultiPlot = TRUE;
plot.ChartY(niVector, (double) 1/pSeries->GetFs()); // crashes
delete pBuffer;
}
When I step through in the debugger, it looks like NiGraph gets created okay. In fact, I can see it on the dialog. However calling ChartY is giving me a runtime error. I suspect I am missing something to do with ActiveX but I'm not sure what.
Thanks, Nick
Solved! Go to Solution.
07-06-2009 11:53 AM
Sorry, this is resolved. I had a stupid error and was passing a zero-length vector to ChartY.
I dicovered that way up on the call stack a exception was being thrown because of this.