Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing a CNiGraph Sink Map

This is long, but there are only three relatively simple questions.  i.e. what are the IID and  CLSID values to use for a sink map.  I've included a list of everything I've done so far to eliminate as many questions as may be posed.

I'm attempting to create a sink map for a dynamically created CNiGraph object in Visual C++ 7.1.3088 with Measurement Studio 7.0.0.341.  The purpose of the sink map is to intercept the right-click event on a CNiGraph object and display a popup menu.  This is the first time I've attempted to create a sink map so I'm a little lost and have a few questions on obtaining the correct IID's and CLSID's.

I've followed the directions to create a CCmdTarget object in Microsoft KB 181845, How to create a sink interface in a MFC-based COM client, but am stuck.  Below are the steps I've taken and some of the questions I have.  All the references to selecting functions are made in reference to the Visual Studio IDE.  i.e. Project->Add Class means select the project menu and then select the add class option.  Please, correct me wherever I'm wrong.

1. Created a CCmdTarget inherited class with automation in the class wizard (Project->Add Class).  This object is called CGraphViewGraphExt.
2. Get the idl file for the CNiGraph object by going to Tools->OLE/COM Object Viewer.  Expand Type Libraries in the left tree, scroll down to National Instruments CW UI 6.0 (Ver 1.6), right-click on it, and select view.  I then save this file as cwui.idl to save myself the trouble of having to dig in the OLE/COM object viewer over and over.
3. Per the directions in KB 181845 step 2, I find the IID of the CNiGraph, which is CWGraph.  My first question is which uuid do I use to reprsent the IID value?

I see in the cwui.idl file that there is a coclass CWGraph which uses the interfaces of _DCWGraph and _DCWGraphEvents which I assume is what I want.  This has a uuid of B68DBFAB-16A0-11CE-80BF-0020AF31CEF9.  Do I use this value as the IID or do I use the uuid at the top of the cwuid.idl file represented by D940E4E4-6079-11CE-88CB-0020AF6845F6.  This uuid represents the entire National Instruments CW UI 7.0 cwui.ocx typelib.  NOTE: I do not know why in the OLE/COM viewer the UI is titled with a version number 6.0 (see step 1 above) and why it is written as 7.0 in the cwui.idl file.  These are the same two files.

At the moment I'm using the CWGraph UUID of B68DBFAB-16A0-11CE-80BF-0020AF31CEF9 to represent my IID value step 2 of KB 181845.

4. After the graph is created with the command:
void CDialogWIndow::CreateGraph() {

    m_niGraph.Create("", WS_VISIBLE, CRect(0, 0, 0, 0), this, m_iNumGraphs, NULL, FALSE, bstrLic);   // resizing takes place later

  //  I make the following function calls per the step 3 in KB 181845.

    m_pGraphViewExt = new CGraphViewGraphExt();      //   create the inherited CCmdTarget object
    LPUNKNOWN pUnkSink = m_pGraphViewExt->GetIDispatch(FALSE);   // get a pointer to sinks IUnknown  
    AfxConnectionAdvise(m_pUnkSrc, IID_IGraphViewGraphExt, pUnkSink, FALSE, &m_dwCookie);   // create connection between source and sink
}

CDialogWindow is a CDialog inherited class.  The variables not declared above are defined as private members of CDialogWindow and have the following declarations:

CGraphViewGraphExt m_pGraphViewExt;
LPUNKNOWN m_pUnkSrc;
DWORD m_dwCookie;
/*   CWGraph UUID as defined by cwui.idl - B68DBFAB-16A0-11CE-80BF-0020AF31CEF9   */
static const IID IID_IGraphViewGraphExt =
{ 0xB68DBFAB, 0x16A0, 0x11CE, { 0x80, 0xBF, 0x00, 0x20, 0xAF, 0x31, 0xCE, 0xF9 } };  

My next question refers to question 3 on KB 181845.  m_pUnkSrc is defined by calling CoCreateInstance.  CoCreateInstance requires a CLSID.  How do I obtain the CLSID for the CNiGraph I create?  I haven't called CoCreateInstance in my code yet because I don't know how to obtain this value.  However, would the call look like CoCreateInstance(/* whatever the CLSID of CWGraph is*/, NULL, CLSCTX_SERVER, IID_IGraphViewGraphExt, (LPVOID*)m_pUnkSrc);   ?  i.e. do those appear to be the correct parameters?

This is where I'm stuck at.  Thanks in advance.

0 Kudos
Message 1 of 3
(4,452 Views)
Hello

You would use the clsid of the CWGraph, not of the cwui type lib.

B68DBFAB-16A0-11CE-80BF-0020AF31CEF9

I attached two examples here. Dynamic graph events shows you how you would hook up events to a dynamically created graph control. UsingMStudioContextmenu.zip shows how you could use the mouse up event to set up a context menu on the graph. You can combine the two to get what you need.

After hooking up the events dynamically, you will see first chance exceptions being generated in the output window. These are "member not found" exceptions and can be ignored. These happen if you only define handlers for some of the events associated with the graph, but not all. If you want to get rid of the exceptions, you will need to define handlers for all the graph events, even if you dont use them. These also occur if you do not define stock properties for the cwgraph control. But these exceptions will not have any detrimental effects. This is just MFC behavior.

I generated the dispatch map protypes by using VC to add event handlers from a graph in another project. You get something like the following with VC.

ON_EVENT(<some other dlg class>, IDC_CWGRAPH2, DISPID_CLICK, ClickCwgraph2, VTS_NONE)

I change it to

DISP_FUNCTION_ID(<sink class name>,"Click",DISPID_CLICK,ClickCwgraph1,VT_EMPTY,VTS_NONE)

and added the appropriate handler function.

I hope this helps

Message Edited by bilalD on 05-11-2006 10:18 AM

Bilal Durrani
NI
Download All
0 Kudos
Message 2 of 3
(4,437 Views)
Thanks.  That was a huge help. 
0 Kudos
Message 3 of 3
(4,426 Views)