这是我的代码。
char BPP[5];
int result, err;
result = GetPrivateProfileStringA("abc", "cba", NULL, BPP, 5, "D:\\aefeaf.ini"); // result = 0
result = _get_errno(&err); // result = 0, err = 0
result = GetLastError(); // result = 0
以及来自MSDN的描述:In the event the initialization file specified by lpFileName is not found, or contains invalid values, this function will set errorno with a value of '0x2' (File Not Found). To retrieve extended error information, call GetLastError.
最后一个参数是随机的,文件不存在。但是 GetLastError() 仍然返回 0。有人可以向我解释为什么它没有返回 2 吗?
编辑:正如@JochenKalmbach 建议的那样,我确保我的项目没有使用 C++/CLI。@claptrap 说 errorno 是一个错字(应该是errno),我在上面的代码中添加了 _get_errno 。但是,所有错误代码返回都是 0。非常感谢任何帮助。