Absolute path of executable start directory

房东的猫 提交于 2019-12-23 04:43:31

问题


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,


回答1:


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




回答2:


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




回答3:


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

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



来源:https://stackoverflow.com/questions/1105968/absolute-path-of-executable-start-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!