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.