Skip to content

Commit 8c006c3

Browse files
committed
Fix build for Microsoft and mingw-w64 compilers
Prior to this change only original mingw worked.
1 parent ad4d5a8 commit 8c006c3

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.exe
2+
*.obj

battstatus.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Sample output:
1414
It can optionally show verbose information and prevent sleep. Use option --help
1515
to see the usage information.
1616
17-
g++ -std=c++11 -o battstatus battstatus.cpp -lntdll -lpowrprof
17+
cl /W4 /wd4127 battstatus.cpp user32.lib powrprof.lib
18+
g++ -Wall -std=c++11 -o battstatus battstatus.cpp -lpowrprof
1819
1920
https://github.com/jay/battstatus
2021
*//*
@@ -36,9 +37,26 @@ GNU General Public License for more details.
3637

3738
#define _WIN32_WINNT 0x0501
3839

40+
#ifndef _CRT_SECURE_NO_WARNINGS
41+
#define _CRT_SECURE_NO_WARNINGS
42+
#endif
43+
44+
#define WIN32_NO_STATUS
3945
#include <windows.h>
40-
#include <powrprof.h>
46+
#undef WIN32_NO_STATUS
47+
48+
#ifdef __MINGW32__
49+
#include <_mingw.h>
50+
#ifdef __MINGW64_VERSION_MAJOR
51+
#include <ntstatus.h>
52+
#else
4153
#include <ddk/ntddk.h>
54+
#endif
55+
#else
56+
#include <ntstatus.h>
57+
#endif
58+
59+
#include <powrprof.h>
4260

4361
#include <assert.h>
4462
#include <limits.h>
@@ -562,6 +580,10 @@ cerr <<
562580

563581
int main(int argc, char *argv[])
564582
{
583+
NTSTATUS (NTAPI *RtlGetVersion)(RTL_OSVERSIONINFOW *lpVersionInformation) =
584+
(NTSTATUS (NTAPI *)(RTL_OSVERSIONINFOW *))
585+
GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlGetVersion");
586+
565587
os.dwOSVersionInfoSize = sizeof os;
566588
RtlGetVersion(&os);
567589

0 commit comments

Comments
 (0)