1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

コードが存在する実行ファイル名を知る方法

Last updated at Posted at 2021-06-23

Visual Studio のテストフレームワークを使っていて、テストコードが存在するモジュールのパスを知りたいことがたまにあって、いつも「どうやるんだっけ?」となるのでメモ。

unittest.cpp
TEST_CLASS(TestClass)
{
    static void DummyFunction()
    {
    }

    TEST_METHOD(TestMethod)
    {
        HMODULE hModule{};
        GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<PCWSTR>(DummyFunction), &hModule);

        std::vector<wchar_t> filePath(MAX_PATH);
        GetModuleFileName(hModule, filePath.data(), filePath.size());

        Logger::WriteMessage(filePath.data());  // DummyFunction が存在するモジュールのフルパス
    }
};
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?