Skip to content

Commit

Permalink
build: Add safe Windows.h include
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylskorych committed Oct 31, 2023
1 parent a7e4ee0 commit 783da58
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
3 changes: 1 addition & 2 deletions SimulatorCore/ModelsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <vector>

#ifdef _MSC_VER
#define NOMINMAX
#include <Windows.h>
#include "DyssolWindows.h"

typedef HINSTANCE DYSSOL_LIBRARY_INSTANCE;
typedef FARPROC DYSSOL_CREATE_FUNCTION_TYPE;
Expand Down
2 changes: 1 addition & 1 deletion Utilities/DyssolSystemFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <processthreadsapi.h>
#include <handleapi.h>
#include <Windows.h>
#include "DyssolWindows.h"
#include <tchar.h>
#include <Psapi.h>
#endif
Expand Down
24 changes: 24 additions & 0 deletions Utilities/DyssolWindows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2023, DyssolTEC GmbH.
* All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

/*
* Safely includes <Windows.h> un-defining some Windows defines.
*/

#pragma once

#ifdef _WIN32
#ifdef NOMINMAX
#include <Windows.h>
#undef AddPort
#undef CreateFile
#undef GetObject
#else
#define NOMINMAX
#include <Windows.h>
#undef NOMINMAX
#undef AddPort
#undef CreateFile
#undef GetObject
#endif
#endif
2 changes: 1 addition & 1 deletion Utilities/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifdef _MSC_VER
#include <corecrt_io.h>
#include <direct.h>
#include <Windows.h>
#include "DyssolWindows.h"
#else
#include <locale>
#include <codecvt>
Expand Down
4 changes: 1 addition & 3 deletions Utilities/StringFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#include "StringFunctions.h"
#ifdef _MSC_VER
#include <Windows.h>
#undef AddPort
#undef CreateFile
#include "DyssolWindows.h"
#else
#include <codecvt>
#endif
Expand Down
1 change: 1 addition & 0 deletions Utilities/Utilities.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<ClInclude Include="DyssolTypes.h" />
<ClInclude Include="DyssolDefines.h" />
<ClInclude Include="DyssolUtilities.h" />
<ClInclude Include="DyssolWindows.h" />
<ClInclude Include="FileSystem.h" />
<ClInclude Include="StringFunctions.h" />
<ClInclude Include="TaskFuture.h" />
Expand Down
3 changes: 3 additions & 0 deletions Utilities/Utilities.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<ClInclude Include="DyssolFilesystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DyssolWindows.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="FileSystem.cpp">
Expand Down

0 comments on commit 783da58

Please sign in to comment.