Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

AfxConnectionAdvise and ASSERT error with CNiGraph dynamic creation

I've implemented a sink map for the CNiGraph control in Visual Studio 2k3 with Measurement Studio 7.0.0.341.  I've attached a sample application to outline my problem.

My dialog window has a private member, CNiGraph pointer.  I create the CNiGraph object, call the Create function to create the window, and then call AfxConnectionAdvise to successfully connect my CCmdTarget object to the graph.  Later, I call AfxConnectionUnadvise and DestroyWindow to remove the graph.  The second time I create the graph using the same pointer, I get an assertion error in winocc.cpp with the following line:

ASSERT(m_pCtrlSite != NULL);    // not an OLE control (not yet, at least)

My research on this forum has found that most support suggests calling AfxEnableControlContainer() during InitInstance.  This is done and is not the problem.  When I remove the AfxConnection(Un)Advise calls, I can create, destroy, and recreate the graph.  When those functions are attached to the CNiGraph control, however, the application causes this assertion error and I've yet to figure out how to fix the problem.  Any help would be greatly appreciated.

To replicate the problem with the attached project, compile and run, then click the create button, then destroy.  The second time you click the create button, the application will fail with the assertion error (and a COleException error).  Hitting the continue button in the debugger will come back with a NI:CNiOleException.

Warning: CreateInterface returning scode = E_POINTER ($80004003).
First-chance exception at 0x7c81eb33 in graph_failure.exe: Microsoft C++ exception: NI::CNiOleException @ 0x0012ec48.


0 Kudos
Message 1 of 3
(4,435 Views)
Hey Antadam,

I believe the reason you are getting this error is because in your code you are setting the ID of your new graph object to 0 and then 1.  I believe these are reserved values.  If you set your initial value of i to a higher value, I was able to create and delete the control no problem.  Just post back if this doesn't seem to resolve the issue.  Also there is an example that programmatically creates a graph object.  This might be helpful if you have any further questions.  Have a good weekend!

Link to Example

static int i = 1000; //This value was originally 0

m_niGraph.Create("", WS_VISIBLE, CRect(0, 0, 200, 200), this, i++, NULL, FALSE);

Message Edited by Patrick P. on 05-19-2006 05:32 PM

Pat P.
Software Engineer
National Instruments
0 Kudos
Message 2 of 3
(4,421 Views)
That was the problem so thank you.  For anyone who runs into something similar, my code will not work if you use the ID of 1000 one of my buttons has the resource ID starting at 1000.  The concept was correct though, so thanks again.
0 Kudos
Message 3 of 3
(4,406 Views)