Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget update #38

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true

# Spell checker configuration
spelling_exclusion_path = spelling.dic

[*.{h,cpp,ixx}]
end_of_line = crlf
indent_size = 4
Expand Down
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<UseFullPaths>true</UseFullPaths>
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>

<!-- Enables recommended Security Development Lifecycle (SDL) checks.
These checks change security-relevant warnings into errors, and set additional secure code-generation features. -->
<SDLCheck>true</SDLCheck>

<!-- For development purposes, All warnings can be used to discover useful compiler warnings.
This requires also that some warnings need to be disabled from this all warning list. -->
<WarningLevel Condition="'$(NETPBM_WIC_CODEC_ALL_WARNINGS)'!=''">EnableAllWarnings</WarningLevel>
Expand Down
2 changes: 2 additions & 0 deletions spelling.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

hkey
4 changes: 4 additions & 0 deletions src/errors.ixx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright (c) Victor Derks.
// SPDX-License-Identifier: MIT

module;

#include "macros.h"

export module errors;

import <win.h>;
Expand Down
10 changes: 10 additions & 0 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@
// Use std::format directly to get compile time checking of the string arguments.
#define TRACE(fmt, ...) OutputDebugStringA(std::format(fmt __VA_OPT__(,) __VA_ARGS__).c_str())
#endif

// Include sal.h as workaround that IntelliSense in VS 2020 17.9 fails to parse #import <win.h>
#ifdef __INTELLISENSE__
#define _AMD64_
#include <sal.h>
#include <winreg.h>
#include <libloaderapi.h>
#include <combaseapi.h>
#include <cassert>
#endif
14 changes: 4 additions & 10 deletions src/netpbm-wic-codec.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -113,7 +113,6 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -127,7 +126,6 @@
<ClCompile>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -141,7 +139,6 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/FS %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand All @@ -154,7 +151,6 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand All @@ -168,7 +164,6 @@
<ClCompile>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/FS %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand All @@ -185,7 +180,6 @@
<ClCompile>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
Expand Down Expand Up @@ -231,13 +225,13 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>
4 changes: 4 additions & 0 deletions src/netpbm_bitmap_frame_decode.ixx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright (c) Victor Derks.
// SPDX-License-Identifier: MIT

module;

#include "macros.h"

export module netpbm_bitmap_frame_decode;

import <std.h>;
Expand Down
2 changes: 1 addition & 1 deletion src/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
</packages>
4 changes: 4 additions & 0 deletions src/pnm_header.ixx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright (c) Victor Derks.
// SPDX-License-Identifier: MIT

module;

#include "macros.h"

export module pnm_header;

import <std.h>;
Expand Down
163 changes: 80 additions & 83 deletions src/util.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -16,118 +16,115 @@ import errors;
[[nodiscard]] HMODULE get_current_module() noexcept
{
HMODULE module;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<PCTSTR>(get_current_module), &module);
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<PCWSTR>(get_current_module), &module);

return module;
}

export
export constexpr std::byte operator"" _byte(const unsigned long long int n)
{
constexpr std::byte operator"" _byte(const unsigned long long int n)
{
return static_cast<std::byte>(n);
}


[[nodiscard]] inline const char* pixel_format_to_string(const GUID& guid) noexcept
{
if (guid == GUID_WICPixelFormat2bppGray)
return "GUID_WICPixelFormat2bppGray";
return static_cast<std::byte>(n);
}

if (guid == GUID_WICPixelFormat4bppGray)
return "GUID_WICPixelFormat4bppGray";

if (guid == GUID_WICPixelFormat8bppGray)
return "GUID_WICPixelFormat8bppGray";
export [[nodiscard]] inline const char* pixel_format_to_string(const GUID& guid) noexcept
{
if (guid == GUID_WICPixelFormat2bppGray)
return "GUID_WICPixelFormat2bppGray";

if (guid == GUID_WICPixelFormat16bppGray)
return "GUID_WICPixelFormat16bppGray";
if (guid == GUID_WICPixelFormat4bppGray)
return "GUID_WICPixelFormat4bppGray";

if (guid == GUID_WICPixelFormat24bppRGB)
return "GUID_WICPixelFormat24bppRGB";
if (guid == GUID_WICPixelFormat8bppGray)
return "GUID_WICPixelFormat8bppGray";

if (guid == GUID_WICPixelFormat48bppRGB)
return "GUID_WICPixelFormat48bppRGB";
if (guid == GUID_WICPixelFormat16bppGray)
return "GUID_WICPixelFormat16bppGray";

return "Unknown";
}

[[nodiscard]] inline std::wstring guid_to_string(const GUID& guid)
{
std::wstring guid_text;
if (guid == GUID_WICPixelFormat24bppRGB)
return "GUID_WICPixelFormat24bppRGB";

guid_text.resize(39);
VERIFY(StringFromGUID2(guid, guid_text.data(), static_cast<int>(guid_text.size())) != 0);
if (guid == GUID_WICPixelFormat48bppRGB)
return "GUID_WICPixelFormat48bppRGB";

// Remove the double null terminator.
guid_text.resize(guid_text.size() - 1);
return "Unknown";
}

return guid_text;
}
export [[nodiscard]] inline std::wstring guid_to_string(const GUID& guid)
{
std::wstring guid_text;

[[nodiscard]] inline std::wstring get_module_path()
{
std::wstring path(100, L'?');
size_t path_size;
size_t actual_size;
guid_text.resize(39);
VERIFY(StringFromGUID2(guid, guid_text.data(), static_cast<int>(guid_text.size())) != 0);

do
{
path_size = path.size();
actual_size = ::GetModuleFileName(get_current_module(), path.data(), static_cast<DWORD>(path_size));
// Remove the double null terminator.
guid_text.resize(guid_text.size() - 1);

if (actual_size + 1 > path_size)
{
path.resize(path_size * 2, L'?');
}
} while (actual_size + 1 > path_size);
return guid_text;
}

path.resize(actual_size);
return path;
}
export [[nodiscard]] inline std::wstring get_module_path()
{
std::wstring path(100, L'?');
size_t path_size;
size_t actual_size;

template<>
struct std::formatter<winrt::hresult> : std::formatter<int32_t>
do
{
auto format(const winrt::hresult& result, std::format_context& ctx) const
path_size = path.size();
actual_size = ::GetModuleFileName(get_current_module(), path.data(), static_cast<DWORD>(path_size));

if (actual_size + 1 > path_size)
{
return std::formatter<int32_t>::format(result.value, ctx);
path.resize(path_size * 2, L'?');
}
};
} while (actual_size + 1 > path_size);

inline void check_hresult(const winrt::hresult result, const winrt::hresult result_to_throw)
{
if (result < 0)
throw_hresult(result_to_throw);
}
path.resize(actual_size);
return path;
}

[[nodiscard]] constexpr bool failed(const winrt::hresult result) noexcept
export template<>
struct std::formatter<winrt::hresult> : std::formatter<int32_t>
{
auto format(const winrt::hresult& result, std::format_context& ctx) const
{
return result < 0;
return std::formatter<int32_t>::format(result.value, ctx);
}
};

template<typename T>
T* check_in_pointer(_In_ T * pointer)
{
if (!pointer)
winrt::throw_hresult(error_invalid_argument);
export inline void check_hresult(const winrt::hresult result, const winrt::hresult result_to_throw)
{
if (result < 0)
throw_hresult(result_to_throw);
}

return pointer;
}
export [[nodiscard]] constexpr bool failed(const winrt::hresult result) noexcept
{
return result < 0;
}

template<typename T>
T* check_out_pointer(T * pointer)
{
if (!pointer)
winrt::throw_hresult(error_pointer);
export template<typename T>
T* check_in_pointer(_In_ T* pointer)
{
if (!pointer)
winrt::throw_hresult(error_invalid_argument);

return pointer;
}
return pointer;
}

inline void check_condition(const bool condition, const winrt::hresult result_to_throw)
{
if (!condition)
throw_hresult(result_to_throw);
}
export template<typename T>
T* check_out_pointer(T* pointer)
{
if (!pointer)
winrt::throw_hresult(error_pointer);

return pointer;
}

export inline void check_condition(const bool condition, const winrt::hresult result_to_throw)
{
if (!condition)
throw_hresult(result_to_throw);
}
28 changes: 0 additions & 28 deletions std-header-units/generate_header_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,3 @@

import "std.h";
import "win.h";

import <vector>;
import <fstream>;
import <ios>;
import <sstream>;
import <string>;
import <array>;
import <algorithm>;
import <bit>;
import <mutex>;
import <span>;
import <cstdint>;
import <cstdio>;
import <cstddef>;
import <cassert>;
import <utility>;
import <chrono>;
import <format>;

import <Shlwapi.h>;
import <Unknwn.h>;
import <objidl.h>;
import <winerror.h>;
import <wincodec.h>;
import <Windows.h>;
import <olectl.h>;
import <ShlObj.h>;
import <guiddef.h>;
Loading
Loading