Using LabWindows/CVI 2013, PC (Windows XP)
I'm passing a pointer to a calloc-generated memory block so that when I call an instrument callback certain parameters are available:
ViStatus PLOT_JPlot (struct Level1DataBlock *L1DB_p) {
G_PanelInfo_p = CreatePanelInfoBlock (L1DB_p, PANEL_JPLOT); //a rather complicated routine that uses calloc to create and than initializes a bunch of data structures.
...
iHandle = LoadPanelEx (0, JPlotPanel_UIR_file, JPLOT, __CVIUserHInst); //load the panel from the UIR file
....
status = SetPanelAttribute (iHandle, ATTR_CALLBACK_DATA, (void *)G_PanelInfo_p); //load the pointer into the callback data area for this panel
....
status = CallCtrlCallback (iHandle, JPLOT_CURSORBUTTON, EVENT_COMMIT, 0, 0, 0);
....
}
which results in a call to
int CVICALLBACK CB_JPlotCursorToggle (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
struct PanelInfoConst *G_PanelInfo_p = NULL;
....
switch (event) {
case EVENT_COMMIT:
GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &panelcallbackData_p);
G_PanelInfo_p = (struct PanelInfoConst *)panelcallbackData_p; //wrong pointer here.
...
}
}
G_PanelInfo_p ends up being a pointer to somewhere in hyperspace, and I get a memory error - it's pointing to somewhere outside of the whole process' memory space.
Except that this same bit works perfectly for another window. The only difference is that the other window is actually being displayed on the screen before I call "CallCtrlCallback ()" and with this window it hasn't actually displayed yet.
The memory block is freed when the window is closed.
Keeping in mind this other post:
should I be using the chained-callback feature?
Oh, and while I'm at it, what's supposed to show up in the " void *callbackData" parameter of the callback function? It ends up NULL; I would think that the ATTR_CALLBACK_DATA entry would show up there.