可执行文件起始目录的绝对路径

发布于 2024-07-26 18:52:00 字数 225 浏览 1 评论 0原文

我想弄清楚如何获取我的程序的起始目录。 我正在使用 C 并且可以访问 GLib。 在Linux方面,很简单,程序启动后立即g_get_current_directory,并存储该值以供以后使用。 我尝试在 Windows 上使用相同的方法,但 g_get_current_directory 返回 %APPDATA% 解析的内容。

关于如何使用 C 获取起始目录有什么想法吗?

谢谢,

I am trying to figure out how to grab the start directory for my program. I am using C and have access to GLib. On the Linux side it is easy, g_get_current_directory as soon as the program is launched, and store this value for later use. I tried using the same method on windows but g_get_current_directory returns whatever %APPDATA% resolves to.

Any ideas on how I can grab the starting directory using C?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空名 2024-08-02 18:52:00

标准 C 中没有(除非 C99 中有新内容)。 C本身没有太多文件系统的概念。

Not in standard C (unless there's something new in C99). C itself doesn't have much of a concept of file systems.

柳絮泡泡 2024-08-02 18:52:00

哎呀,找到解决办法了。 如果您有权访问 glib,只需使用:

gchar* g_win32_get_package_installation_directory_of_module(gpointer hmodule);

如果 hmodule 为 NULL 那么它将返回 .exe 的目录

Oops, found the solution. If you have access to glib, simply use:

gchar* g_win32_get_package_installation_directory_of_module(gpointer hmodule);

If hmodule is NULL then it will return the dir for the .exe

半山落雨半山空 2024-08-02 18:52:00

我相信 _getcwd() 正是您所需要的,请查看 MSDN 文档:

http://msdn.microsoft.com/en-us/library/sf98bd4y.aspx

I believe _getcwd() is what you need, have a look here at the MSDN documentation:

http://msdn.microsoft.com/en-us/library/sf98bd4y.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文