C6381

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

warning C6381: Shutdown API <function> requires a valid dwReason or lpMessage

This warning is issued if InitiateSystemShutdownEx is called:

  • Without passing a valid shutdown reason (dwReason). If dwReason parameter is zero, the default is an undefined shutdown. By default, it is also an unplanned shutdown. You should use one of the System Shutdown Reason Codes for this parameter.

  • Without passing a shutdown message (lpMessage).

We recommend that you use appropriate parameters when calling this API to help system administrators determine the cause of the shutdown.

The following code generates this warning because dwReason is zero and lpMessage is null:

void f()  
{  
  //...  
  BOOL bRet;  
  bRet = InitiateSystemShutdownEx( NULL,  
                                   NULL, // message  
                                   0,          
                                   FALSE,      
                                   TRUE,       
                                   0);  // shutdown reason  
  // ...  
}  

To correct this warning, specify dwReason and lpMessage as shown in the following code:

#include <windows.h>  
void f()  
{  
  //...  
  BOOL bRet;  
  bRet = InitiateSystemShutdownEx( NULL,  
                               "Hardware Failure",  // message    
                               0,          
                               FALSE,      
                               TRUE,       
                               SHTDN_REASON_MAJOR_HARDWARE ); // reason  
  // ...  
}  

Show: