Skip to content

Commit

Permalink
Fix build for Microsoft and mingw-w64 compilers
Browse files Browse the repository at this point in the history
Prior to this change only original mingw worked.
  • Loading branch information
jay committed Aug 6, 2017
1 parent ad4d5a8 commit 8c006c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.exe
*.obj
26 changes: 24 additions & 2 deletions battstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Sample output:
It can optionally show verbose information and prevent sleep. Use option --help
to see the usage information.
g++ -std=c++11 -o battstatus battstatus.cpp -lntdll -lpowrprof
cl /W4 /wd4127 battstatus.cpp user32.lib powrprof.lib
g++ -Wall -std=c++11 -o battstatus battstatus.cpp -lpowrprof
https://github.com/jay/battstatus
*//*
Expand All @@ -36,9 +37,26 @@ GNU General Public License for more details.

#define _WIN32_WINNT 0x0501

#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#define WIN32_NO_STATUS
#include <windows.h>
#include <powrprof.h>
#undef WIN32_NO_STATUS

#ifdef __MINGW32__
#include <_mingw.h>
#ifdef __MINGW64_VERSION_MAJOR
#include <ntstatus.h>
#else
#include <ddk/ntddk.h>
#endif
#else
#include <ntstatus.h>
#endif

#include <powrprof.h>

#include <assert.h>
#include <limits.h>
Expand Down Expand Up @@ -562,6 +580,10 @@ cerr <<

int main(int argc, char *argv[])
{
NTSTATUS (NTAPI *RtlGetVersion)(RTL_OSVERSIONINFOW *lpVersionInformation) =
(NTSTATUS (NTAPI *)(RTL_OSVERSIONINFOW *))
GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlGetVersion");

os.dwOSVersionInfoSize = sizeof os;
RtlGetVersion(&os);

Expand Down

0 comments on commit 8c006c3

Please sign in to comment.