LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

MessageBox causes program lockup

Hi!

 

I'm having some trouble with an callback/interruption lockup. When my program encounters an error I want to show the user a message, using the MessageBoxExA function provided by Windows. In the background I have sevaral callbacks running (timers, communication stuff, etc.).

 

static void showPopup(char* title, char* text, int icon)
{
HWND windows_panel_handle = NULL;
GetPanelAttribute(UI.windowHandle, ATTR_SYSTEM_WINDOW_HANDLE, (int*)&windows_panel_handle);
MessageBoxExA(windows_panel_handle, text, title, MB_SETFOREGROUND | MB_TOPMOST | MB_SYSTEMMODAL | icon | MB_OK | MB_DEFBUTTON1, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
return;
}

Behaviour in about 50 % of the cases: The program passes the MessageBoxExA function call and I can hear the associated sound, but no box shows up (or turns up behind my main panel, unclear). All interaction with the main panel is locked by the MessageBox function. The program does not pass the return in the above function.

Best current theory is that my other callbacks interject while I'm setting up the messagebox. Is there any way I can temporarily block all other callbacks/system events until MessageBoxExA has finished running (supposing that's the problem)?

Probably relevant detail: The call to showPopup is through-some-calls initiated by a callback triggered by received data from a connected device. Could the cause be that it's run inside a callback?

 

Thanks!

0 Kudos
Message 1 of 3
(891 Views)

When coming to the interaction between Windows and CVI functions some surprises can arise...

It is well possible that some ongoing function collides with MessageBoxXX function.To prevent UI timers callbacks to execute you can call SuspendTimerCallbacks () function, followed by a call to ResumeTimerCallbacks () after the critical function terminates (NOTE: they operate only on timers started in the same thread). Similarly, async timers can be paused and resumed by calling SuspendAsyncTimerCallbacks () and ResumeAsyncTimerCallbacks ().

Different is the case for functions spawned in separate threads: there isn't a built-in function to suspend them so you'll need to develop some strategy specific to your program.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(884 Views)

Thanks, that's what I was looking for. I added the suspend and resume asyncTimer functions, but unfortunately that doesn't seem to be the core problem in this case. It turns out that it's not just that the showPopup function is interrupted by a callback, it is also itself interrupting a callback first, and it is likely the first callback that is causing the deadlock (contains a function that should not be in a callback). That I don't get the messagebox may simply be a consequence of the freeze due to the first callback.

 

I think i'll make a new thread for the continuation, as I'm drifting away from the original subject.

0 Kudos
Message 3 of 3
(854 Views)