For some reason my shutdown function that i'm making won't work.
I get this error:

In function `void shutdown()':
expected `,' or `...' before numeric constant


Here is my coding:

#include <windows.h>

void shutdown();
void shutdown()
{
BOOL WINAPI ExitWindowsEx(UINT EWX_REBOOT,
DWORD SHTDN_REASON_MAJOR_HARDWARE);
return;
}

int main()
{
shutdown();
}

The problem is with the line that starts with BOOL WINAPI. I have tried a bunch of things but none of them work.

BOOL WINAPI ExitWindowsEx(UINT EWX_REBOOT,
DWORD SHTDN_REASON_MAJOR_HARDWARE);

This somehow looks like you are declaring a function .
Though what you need is to call it.

I am not a Windows expert but try this.

ExitWindowsEx(UINT EWX_REBOOT,
DWORD SHTDN_REASON_MAJOR_HARDWARE);

Also check if the function is embedded into a namespace.

BOOL WINAPI ExitWindowsEx(UINT EWX_REBOOT,
DWORD SHTDN_REASON_MAJOR_HARDWARE);

This somehow looks like you are defining a function .
Though what you need is to call it.

I am not a Windows expert but try this.

ExitWindowsEx(UINT EWX_REBOOT,
DWORD SHTDN_REASON_MAJOR_HARDWARE);

I tried that and got 2 new errors.

In function `void shutdown()':
expected primary-expression before numeric constant
expected primary-expression before "SHTDN_REASON_MAJOR_HARDWARE"

I am absolutely sorry,

ExitWindowsEx(EWX_REBOOT, SHTDN_REASON_MAJOR_HARDWARE);

this should work out,

I forgot to remove the data-types in your function.

Though I am worried whether SHTDN_REASON_MAJOR_HARDWARE exists.

Thank you it worked. And you were right that SHTDN_REASON_MAJOR_HARDWARE does not exist. MSDN said that I could use it but apparently they lied! Anyway do you know a reason that I could fill in instead for this parameter?

I'm trying all of MSDN's reasons but none of them are working. My compiler says that they are all undeclared. I tried putting DWORD in front of them but then it says that it expects a primary-expression before SHTDN_REASON_MAJOR_HARDWARE.

I Never Used Windows programming before, But I think that You will need to include a file known as reason.h

#include <reason.h>

You were right. I needed to actually download the file and the program worked but my computer didn't restart,the application just closed.

Thanks! Everything works great. I'm new to windows.h and trying to learn all of it's functions.

This question has already been answered. Start a new discussion instead.