张洋 4 weeks ago
parent
commit
afc378ca06
1 changed files with 4 additions and 1 deletions
  1. 4 1
      DuiLib/Core/UIManager.cpp

+ 4 - 1
DuiLib/Core/UIManager.cpp

@@ -96,10 +96,13 @@ namespace DuiLib
 #endif
 			FILE* f = NULL;
 			// 保护:单个日志超过 4MB 就不再追加,避免在收银机上长期运行把日志写到失控。
+			// 注意:GetFileAttributesEx 是 TCHAR 宏(Unicode 工程下展开为 ...ExW),
+			// 必须传 TCHAR 的 path,不能传 Narrow(path) 得到的 UTF-8 char*(否则 C2664)。
 			WIN32_FILE_ATTRIBUTE_DATA fad = { 0 };
-			if (::GetFileAttributesEx(Narrow(path), GetFileExInfoStandard, &fad)
+			if (::GetFileAttributesEx(path, GetFileExInfoStandard, &fad)
 				&& fad.nFileSizeHigh == 0 && fad.nFileSizeLow >= (4u * 1024u * 1024u))
 				return;
+			// fopen_s 只吃 char*(窄字符路径),这里才需要 UTF-8 的 Narrow(path)
 			if (fopen_s(&f, Narrow(path), "a") == 0 && f != NULL)
 			{
 				fprintf(f, "[%8u][T%5u] %s\n", (unsigned)::GetTickCount(), (unsigned)::GetCurrentThreadId(), utf8);