LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NULL user argument in InstallWinMsgCallback() callback when fires EVENT_NEWHANDLE

 I admit this is a quite esoteric bug in toolbox functions 🙂 

InstallWinMsgCallback() last parameter is a pointer to user data to be passed to the callback function. There is a inner mechanism to reinstall the CVI managed WndProc (used to trap messages to be sent to the calback)  when the original window handle is destroyed by CVI.

When this happens, the message EVENT_NEWHANDLE is posted to the callback to inform the user program of this event.
In this special case, the user data pointer is always NULL and it has not the value specified when InstallWinMsgCallback was called, 


The buggy function is in toolbox.c:

/-------------------------------------------------------------------------------------------------
// Function: DeferredReinstallHandler
//
// Purpose:  Re-install the WT WndProc for the panel associated with the passed handler object, and
//           notify all user callbacks of the new HWND window handle.  A post-deferred call to this
//           function is made in the WndProc when the window gets temporarily destroyed by CVI--
//           this is the restoration routine.
//
// Return:   void
//-------------------------------------------------------------------------------------------------
static void CVICALLBACK DeferredReinstallHandler (void* phandler)
{
    size_t			numLinks, linkPosInList;
    MSG_FUNC_LINK	*plink;

    GetPanelAttribute (((MSG_CB_HANDLER*)phandler)->hpanel, ATTR_SYSTEM_WINDOW_HANDLE,
                       &(((MSG_CB_HANDLER*)phandler)->hwindow));
    InsertMsgHandlerWndProc ((MSG_CB_HANDLER*)phandler);
    if (((MSG_CB_HANDLER*)phandler)->winMsgEnabled)
        {
        numLinks = ListNumItems (((MSG_CB_HANDLER*)phandler)->links);
        for (linkPosInList = 1; linkPosInList <= numLinks; linkPosInList++)
            {
            plink = ListGetPtrToItem (((MSG_CB_HANDLER*)phandler)->links,
                                            linkPosInList);
            (plink->UserCallback) (((MSG_CB_HANDLER*)phandler)->hpanel, EVENT_NEWHANDLE,
                                   (unsigned int *)&(((MSG_CB_HANDLER*)phandler)->hwindow), 0, NULL);
            }
        }
    return;
}

and the fix is simply to pass, in place of NULL, the correct pointer:

   (plink->UserCallback) (((MSG_CB_HANDLER*)phandler)->hpanel, EVENT_NEWHANDLE,
                          (unsigned int *)&(((MSG_CB_HANDLER*)phandler)->hwindow), 0, plink->callbackData);

 

Carlo A.
Megaris




Message 1 of 1
(2,663 Views)