NT状态未在此范围内声明
NTSTATUS not declared in this scope
我可以在 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
修复了问题。
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明