InDesign2023 プラグイン(Windows用) 作成で遭遇したエラー

InDesign 2023 のプラグインWindows用)のサンプルをビルドしようとした際、最初に躓いたのでメモ。


結論(?):

InDesign SDKでは、Visual Studio 2022 - v17.1.6 を開発環境に指定している。

私の環境では Visual Studio 2022 - v17.6.2 だった。

v17.5の修正が影響してた(と思う。VSのバージョンを戻してまで検証してない)


現象2つ:

エラー C1189 #error: "You need to update xlocnum hack header by copying over the header from your Visual Studio installation and applying the same changes as to the previous versions. Be careful, this header also changes between minor versions of Visual Studio. MSC_VER was: " VALUE_TO_STRING(_MSC_VER) BasicDialog …略…\xlocnum_hack.h 27

SDKで指定された VSのバージョン以外の環境でビルドすると出ることがある。VS2019の時も出た記憶がある。

(自環境のバージョンを上げてしまった場合など。バージョンダウンだと出ないかも?)

community.adobe.com

これを回避したら下記のエラーに変わった。

エラー C2039 'c_str': 'std::locale' のメンバーではありません

…略…\xlocnum_hack_vs2022_17_1.h(157,57): error C2039: 'c_str': 'std::locale' のメンバーではありません

無いの?🙄


回避:

本来なら公式が指定する VS2022 v17.1.6 環境を用意すべきなんだろうけど…。

ちょっと横着して下記で対応した。

1. SDKの中にある xlocnum_hack.h に追記

 #elif _MSC_VER >= 1931 && _MSC_VER < 1932 // VS 2022 version 17.1
    #include "xlocnum_hack_vs2022_17_1.h"
+ #elif _MSC_VER >= 1932 && _MSC_VER < 1935 // VS 2022 version 17.2 - 17.4. "Added for local environment."
+   #include "xlocnum_hack_vs2022_17_1.h"
+ #elif _MSC_VER >= 1935 && _MSC_VER < 1937 // VS 2022 version 17.5 - 17.6(1936).  "Added for local environment."
+   #include "xlocnum_hack_vs2022_17_1_custom.h"
 #else

2. 同じフォルダ内にある xlocnum_hack_vs2022_17_1.h をコピーして xlocnum_hack_vs2022_17_1_custom.h を作成し、下記の書き換え。

    static size_t _Getcat(const locale::facet** _Ppf = nullptr,
        const locale* _Ploc = nullptr) { // return locale category mask and construct standard facet
        if (_Ppf != nullptr && *_Ppf == nullptr) {
-            *_Ppf = new numpunct<_Elem>(_Locinfo(_Ploc->c_str()), 0, true);
+            *_Ppf = new numpunct<_Elem>(_Locinfo(_Ploc->_C_str()), 0, true); // for VS17.5 and later
        }
        return _X_NUMERIC;
    }

「'c_str': 'std::locale' のメンバーではありません」について

microsoft/STLChangelog によると、VS 2022 17.5 で修正されたっぽい。

Removed a non-Standard member function locale::c_str(). #3088

そのままズバリ…。

    }

-    _Ret_z_ const char* c_str() const {
+    _Ret_z_ const char* _C_str() const noexcept {
        return _Ptr ? _Ptr->_Name.c_str() : "";
    }

github.com

以上