Skip to content

Instantly share code, notes, and snippets.

@mugwort-rc
Last active May 17, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mugwort-rc/36e883c0d31e037dfb54d6ac24ad82e7 to your computer and use it in GitHub Desktop.
Save mugwort-rc/36e883c0d31e037dfb54d6ac24ad82e7 to your computer and use it in GitHub Desktop.
Visual Studio 2019 v16.8以降 で Windows 8.1 SDK を使用できない問題の解決方法

Visual Studio 2019 v16.8以降 で Windows 8.1 SDK を使用できない問題の解決方法

問題

1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\combaseapi.h(229,21): error C2760: 構文エラー: 予期しないトークン '識別子 '、必要なトークン '型指定子'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\combaseapi.h(229,21): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'

解決方法

いずれかの方法をひとつ選ぶ。

  • Windows 8.1 SDKなんて💩は使わない🗑
  • C/C++/言語/準拠モードを いいえ(/permissive)に設定する
    • この時/std:c++latestを有効にすると/permissiveは働かない(準拠モード/permissive-と同じ)ので、/std:c++17で妥協する必要がある
  • #include <Windows.h>等の前にstruct IUnknown;前方宣言を追加する(参考リンク)
    • gdiplusheaders.hgdiplusstringformat.hの謎宣言がどうしようもないので応急処置はもう出来ない
  • Windows 8.1 SDKを部分的にWindows 10 SDK相当に差し替える

参考

--- a/combaseapi.h 2013-08-21 16:35:14.000000000 +0900
+++ b/combaseapi.h 2021-05-17 19:48:49.394001931 +0900
@@ -215,22 +215,16 @@
#endif
#endif
-// IID_PPV_ARGS(ppType)
-// ppType is the variable of type IType that will be filled
-//
-// RESULTS in: IID_IType, ppvType
-// will create a compiler error if wrong level of indirection is used.
-//
+#ifndef SORTPP_PASS
+
+// This forward declaration has been left where this type was previously defined, to preserve ordering.
extern "C++"
{
- template<typename T> _Post_equal_to_(pp) _Post_satisfies_(return == pp) void** IID_PPV_ARGS_Helper(T** pp)
- {
-#pragma prefast(suppress: 6269, "Tool issue with unused static_cast")
- static_cast<IUnknown*>(*pp); // make sure everyone derives from IUnknown
- return reinterpret_cast<void**>(pp);
- }
+ template<typename T> _Post_equal_to_(pp) _Post_satisfies_(return == pp) void** IID_PPV_ARGS_Helper(T** pp);
}
+#endif // !SORTPP_PASS
+
#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), IID_PPV_ARGS_Helper(ppType)
#else
@@ -373,6 +367,27 @@
#include <wtypesbase.h>
#include <unknwnbase.h>
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+
+// IID_PPV_ARGS(ppType)
+// ppType is the variable of type IType that will be filled
+//
+// RESULTS in: IID_IType, ppvType
+// will create a compiler error if wrong level of indirection is used.
+//
+extern "C++"
+{
+ template<typename T> _Post_equal_to_(pp) _Post_satisfies_(return == pp) void** IID_PPV_ARGS_Helper(T** pp)
+ {
+#pragma prefast(suppress: 6269, "Tool issue with unused static_cast")
+ static_cast<IUnknown*>(*pp); // make sure everyone derives from IUnknown
+ return reinterpret_cast<void**>(pp);
+ }
+}
+
+#endif // defined(__cplusplus) && !defined(CINTERFACE)
+
#include <objidlbase.h>
#include <guiddef.h>
--- a/gdiplusheaders.h 2013-06-18 05:23:06.000000000 +0900
+++ b/gdiplusheaders.h 2021-05-17 16:32:15.169658000 +0900
@@ -897,7 +897,7 @@
UINT GetDownLevelRasterizationLimit() const;
- static UINT Metafile::EmfToWmfBits(
+ static UINT EmfToWmfBits(
_In_ HENHMETAFILE hemf,
_In_ UINT cbData16,
_Out_writes_to_opt_(cbData16, return) LPBYTE pData16,
--- a/gdiplusstringformat.h 2013-06-18 05:23:06.000000000 +0900
+++ b/gdiplusstringformat.h 2021-05-17 16:31:17.791940000 +0900
@@ -222,7 +222,7 @@
));
}
- StringTrimming StringFormat::GetTrimming() const
+ StringTrimming GetTrimming() const
{
StringTrimming trimming;
SetStatus(DllExports::GdipGetStringFormatTrimming(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment