skip to content

Suppress All Microsoft Crt Dialog Boxes

When running automated tests like unit tests, you don’t want faulty code to be halted by CRT dialog boxes, waiting for a user interaction.

The solution in such a situation is to install your own reporting function that does nothing:

#ifdef _WIN32
int stfuHook(int, char*, int* returnValue)
{
  if (returnValue)
    *returnValue = 0;
 
  return true;
}
#endif
 
int main(int argc, char * argv[])
{
#ifdef _WIN32
  _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, stfuHook);
#endif
 
...

}