views:

44

answers:

1

I have WPF application which was migrated from .net3.5 to .net4.0. This application uses an old one C++ library (as I understand this is mixed mode library, means managed-unmanaged). Library moved to .net4 environment with some strange bug which occurs on callback call:

            if (m_pCANCallback)
            m_pCANCallback(m_pCANCallbackPtr, &rxData); 

It passes rxData correctly if VS debugger is attached and it passes NULL if I start application without debugger.

Here is callback function defenition:

void USBCANAdapter::CANDataCallback( void *pThis, RxData *pRxData )

So, at the body of this function pRxData is equal to NULL but it happens only without debugger and only at .net4 environment.

Just in case, callback initialization:

m_pUsbCan->DefineCANMsgCallback( (TUsbCallback)USBCANAdapter::CANDataCallback );

    void CUsbFt::DefineCANMsgCallback(TUsbCallback pCallback, void *pCallbackPtr)
{
    m_pCANCallback = pCallback;
    m_pCANCallbackPtr = pCallbackPtr;
}

Thanks a lot for any advises!

+1  A: 

In my experience, 100% of the time where something works in the debugger, and fails outside of it, the cause is overrunning a function local array.

UPDATE: For example, doing something like this will cause that problem:

 USBCANAdapter::CANDataCallback( void *pThis, RxData *pRxData ) 
 {
       char title[5];
       strcpy(title, "1234567890");
       // :
 }

(Or the overun may be in the calling rountine....)

James Curran
James, could you explain what do you mean?
wow, C++ programming even more hardcore than I could imagine. Thank you for your answer