如何使用 POCO 获取应用程序文件名,如 GetModuleFileName (Win32 API )

How to get Application file name with POCO as in GetModuleFileName (Win32 API )

我尝试找出使用跨平台 POCO c++ lib 获取应用程序的 exe 文件名的方法。

尝试过:

char* FileName ;
FileName =  const_cast<char*>(Application::name());

但我在 FileName char * 中得到的只是 "Application" 我在这里做错了什么?

documentation 说:

application.name: the file name of the application executable

有一个name()方法:

https://github.com/pocoproject/poco/blob/develop/Util/src/Application.cpp#L179 :

const char* Application::name() const
{
    return "Application";
}

我觉得这有点令人困惑。但是,文档是正确的:

处理此问题的正确方法是获取配置 (Application::config()) 并从中检索数据。

不过,πìντα ῥεῖ 对您的原始问题的评论是正确的:无需为语言附带的内容使用 "portable" 库。 main 函数的 argv[0] 定义为包含可执行文件名称。