How to get the %AppData% folder in C?

后端 未结 5 895
予麋鹿
予麋鹿 2020-12-11 03:45

As above, how do I get the AppData folder in Windows using C?

I know that for C# you use Environment.SpecialFolder.ApplicationData

5条回答
  •  佛祖请我去吃肉
    2020-12-11 04:25

    Using the %APPDATA% environment variable will probably work most of the time. However, if you want to do this the official Windows way, you should use use the SHGetFolderPath function, passing the CSIDL value CSIDL_APPDATA or CSIDL_LOCAL_APPDATA, depending on your needs.

    This is what the Environment.GetFolderPath() method is using in .NET.

    EDIT: Joey correctly points out that this has been replaced by SHGetKnownFolderPath in Windows Vista. News to me :-).

提交回复
热议问题