Hi,
Thanks for the simple example showing your problem. I was able to run it and replicate the crash. It looked like it was failing when IMAQdx was calling your callback function you registered. Digging into your provided code, I saw you had the following line:
// Setup a frame done event to be called on each image.
error = IMAQdxRegisterFrameDoneEvent(session, 1, (FrameDoneEventCallbackPtr) FrameDoneCallback, NULL)
I was wondering why you had that cast there, and when I removed it I saw that CVI's compiler complained that the calling convention was mismatched. Looking at your callback function I see that it is not defined with any calling convention but the callback's expected prototype is:
typedef uInt32 (NI_FUNC *FrameDoneEventCallbackPtr)(IMAQdxSession id, uInt32 bufferNumber, void* callbackData);
NI_FUNC is defined to be __stdcall calling convention for our MSVC/CVI interface on Windows. The CVI compiler's default calling convention is __cdecl unless otherwise specified. This is what caused the mismatch. By casting the error away you caused the stack to get messed up during the callback. In many cases it can end up "sort of" working and a problem doesn't immediately appear due to the stack layout. However, when you hit the Stop button, various things get cancelled and the thread doing callbacks ends up with a slightly different stack layout and ends up crashing when calling your function.
I changed your callback function declaration to:
uInt32 NI_FUNC FrameDoneCallback(IMAQdxSession session, uInt32 bufferNumber, void* callbackData)
and now your example works fine.
Hope this clears things up,
Eric