Edit

Share via


Warning C6381

Shutdown API 'function' requires a valid dwReason or lpMessage

Remarks

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's 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.

Code analysis name: SHUTDOWN_API

Example

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
  // ...
}