最近获取Windows版本号,发现win10系统显示6.2版,试了几个API函数都是显示6.2,然后一查,原来MS淘汰了这些API。
那么就只好用PEB来获取系统版本了。
MSDN上面寥寥几句
NtCurrentTeb function (winnt.h)
Article
06/30/2021
2 minutes to read
The NtCurrentTeb routine returns a pointer to the Thread Environment Block (TEB) of the current thread.
Syntax
C++
Copy
_TEB * NtCurrentTeb();
Return value
A pointer to the thread environment block of the current thread.
Requirements
Minimum supported client Available in Windows 7 and later versions of Windows.
Target Platform Universal
Header winnt.h
See also
NtXxx Routines
使用条件倒是很简单
新建个mfc工程
#include <winnt.h>
NtCurrentTeb();
--------------------Configuration: test - Win32 Debug--------------------
Compiling…
testDlg.cpp
Linking…
testDlg.obj : error LNK2001: unresolved external symbol _NtCurrentTeb
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
test.exe - 1 error(s), 0 warning(s)
编译,结果报错了,error LNK2001,缺lib文件,然后也没有找到ntdll.lib,也就是VC6里面没法直接使用这个函数了,那就换个方法,动态加载dll,然后调用这个函数。
H文件
typedef struct _PEB {
BOOLEAN InheritedAddressSpace;
BOOLEAN ReadImageFileExecOptions;
BOOLEAN BeingDebugged;
BOOLEAN BitField;
HANDLE Mutant;
PVOID ImageBaseAddress;
PVOID Ldr;
PVOID ProcessParameters;
PVOID SubSystemData;
PVOID ProcessHeap;
PVOID FastPebLock;
PVOID AtlThunkSListPtr;
PVOID SparePtr2;
ULONG EnvironmentUpdateCount