可変長引数

概要

簡単な可変長引数を体験しましょう。
簡単なところからHm.CppInvokeの雰囲気になれていきましょう。

可変長引数

  • C++側のソース

    Params.dllとしてコンパイル
    #include <windows.h>
    #include <string>
    #include <vector>
    
    #include "HmCppInvoke.h"
    
    using namespace std;
    using namespace Hidemaru;
    
    template<class... PARAMS>
    int getMiniInteger(int num, PARAMS... args) {
    
        int mini = num;
        for (int arg : std::initializer_list<int>{ args... }) {
            if (arg < mini) {
                mini = arg;
            }
        }
    
        return mini;
    }
    
    extern "C" __declspec(dllexport) THmNumber test() {
        Hm.funcDllExport();
    
        try {
            // この数値のうち最小値を求めよ
            auto mini = getMiniInteger(3, 100, 2, 3);
    
            Hm.OutputPane.output(L"最小数値:" + std::to_wstring(mini) + L"\r\n");
        }
        catch (exception& e) {
            // エラー内容をchar → wstring へ
            auto wide_what = Text::Encoding::cp932_to_utf16( e.what() );
            Hm.OutputPane.output(wide_what + L"\r\n");
        }
    
    
        return 1;
    }
  • 秀丸マクロ側のソース

    test.mac
    // Params.dllとしてコンパイルした
    #dll = loaddll(currentmacrodirectory + @"\Params.dll");
     
    // 途中でマクロの文法や型の致命的エラーが発生した場合でもdllを解放する。
    if (version >= 898) { eval "keepdll #dll, 0"; }
     
    #r = dllfuncw(#dll, "test");
     
    freedll(#dll);