MAX_PATH 是否足以保存来自 GetSystemDirectory() 的路径?

Is MAX_PATH enough to hold the path from GetSystemDirectory()?

根据我的理解,该路径将是一个单字母(驱动程序),后跟 "\WINDOWS\SYSTEM32",因此 MAX_PATH 足以容纳由 [=14 填充的路径=]。所以这样做是安全的:

TCHAR dir[MAX_PATH] = {0};
if(GetSystemDirectory(dir, sizeof(dir) / sizeof(*dir)) == 0) {
  // check for GetLastError()
}

还是我遗漏了什么?

GetSystemDirectory (which is ShGetFolderPath) 的推荐替代方案提供的文档对其 pszPath 参数说明如下:

A pointer to a null-terminated string of length MAX_PATH which will receive the path. If an error occurs or S_FALSE is returned, this string will be empty. The returned path does not include a trailing backslash. For example, "C:\Users" is returned rather than "C:\Users\".

所以,是的,MAX_PATH 将是一个足够大的缓冲区大小。