NT状态未在此范围内声明

NTSTATUS not declared in this scope

本文关键字:范围内 声明 状态 NT      更新时间:2023-10-16

我可以在 Linux 上的 mingw64 下编译以下函数作为 Windows 可执行文件。

std::string get_os()
{
std::string os;
std::ostringstream ds;
int ret = 0.0;
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
OSVERSIONINFOEXW osInfo;
*reinterpret_cast<FARPROC*>(&RtlGetVersion) = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
if (nullptr != RtlGetVersion)
{
osInfo.dwOSVersionInfoSize = sizeof osInfo;
RtlGetVersion(&osInfo);
ret = osInfo.dwMajorVersion;
}
int mw = osInfo.dwMinorVersion;
if(ret == 5){
switch (mw)
{
case 0:
// 5.0 = Windows 2000
os = "Windows 2000";
break;
case 1:
// 5.1 = Windows XP
os = "Windows XP";
break;
case 2:
os = "Windows XP Professional";
break;
default:
ds.str(""); ds.clear(); 
ds << "Windows " << mw;
os = ds.str();
break;
}
} else if(ret == 6){
switch (mw)
{
case 0:
os = "Windows Vista";
break;
case 1:
os = "Windows 7";
break;
case 2:
os = "Windows 8";
break;
case 3:
os = "Windows 8.1";
break;
default:
ds.str(""); ds.clear(); 
ds << "Windows " << mw;
os = ds.str();
break;
}
} else if(ret == 10){
os = "Windows 10";
} else {
ds.str(""); ds.clear(); 
ds << "Windows " << mw;
os = ds.str();
}
return os;
}

但是在Windows上,我无法编译它,因为我收到这些未知的错误。为什么? 我想我在Windows上缺少一些库。但是所有必需的东西都应该在 windows.h 中?不应该吗?

NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
^
testos.cpp:135:32: error: 'NTSTATUS' was not declared in this scope
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
^
testos.cpp:135:52: error: expected primary-expression before ')' token
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
^
testos.cpp:138:31: error: 'RtlGetVersion' was not declared in this scope
*reinterpret_cast<FARPROC*>(&RtlGetVersion) = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
^~~~~~~~~~~~~
makefile:2: recipe for target 'windows' failed
make: *** [windows] Error 1

我知道这现在已经很旧了,但以防万一有人遇到同样的问题。

#define NTSTATUS LONG

修复了问题。