链接失败。如何使用'NtQuerySystemTime'窗口功能?
Linking failure. How to use 'NtQuerySystemTime' windows function?
我尝试使用以下简单代码来计算应用程序中的HDD写入速度:
#include <winternl.h>
...
float speed;
double divident;
PLARGE_INTEGER systime0, systime1;
LONGLONG elapsed_time;
...
write_flag = true ;
NtQuerySystemTime(systime0) ;
f_out->write(out_buffer0, chunk_len0);
f_out->write(out_buffer1, chunk_len1);
NtQuerySystemTime(systime1);
elapsed_time = systime1->QuadPart - systime0->QuadPart;
write_flag = false ;
divident = static_cast<double>(chunk_len0 + chunk_len1) / 1.048576 ; // 1.024 * 1.024 = 1.048576; divident yield value 1000000 times greater then value in MB
divident *= 10 ; // I want 'speed' to be in MB/s
speed = divident / static_cast<double>(elapsed_time) ;
...
但它无法链接。
在 MSDN 上,NtQuerySystemTime
文档说没有关联的导入库,我必须使用 LoadLibrary()
和 GetProcAddress()
函数动态链接到Ntdll.dll
。但是我不明白如何使用这些功能。有人可以提供如何使用这些功能的代码示例吗?
这就是您如何使用此功能。
HMODULE hNtDll = GetModuleHandleA("ntdll");
NTSTATUS (WINAPI *NtQuerySystemTime)(PLARGE_INTEGER) =
(NTSTATUS (WINAPI*)(PLARGE_INTEGER))GetProcAddress(hNtDll, "NtQuerySystemTime");
#include <stdio.h>
#include <windows.h>
typedef NTSYSAPI (CALLBACK *LPNTQUERYSYSTEMTIME)(PLARGE_INTEGER);
void main(void)
{
PLARGE_INTEGER SystemTime;
SystemTime = (PLARGE_INTEGER) malloc(sizeof(LARGE_INTEGER));
HMODULE hNtDll = GetModuleHandleA("ntdll");
LPNTQUERYSYSTEMTIME fnNtQuerySystemTime = (LPNTQUERYSYSTEMTIME)GetProcAddress(hNtDll, "NtQuerySystemTime");
if(fnNtQuerySystemTime){
printf("found NtQuerySystemTime function at ntdll.dll address:%pn",fnNtQuerySystemTime);
fnNtQuerySystemTime(SystemTime);
printf("%llxn", SystemTime->QuadPart);
}
free(SystemTime);
}
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 带内存和隔离功能的SQLite
- 问:如何使用C++中的按钮从窗口打开窗口
- 在鼠标按下时移动 SDL2 窗口的功能闪烁窗口并且移动速度不够快
- 您如何在与打开窗口的功能的不同函数中使用Draw函数
- WinAPI - 确定窗口是否具有最大化/还原功能
- 如何将SFML窗口声明为我所有的类功能
- 如何从窗口功能外部访问wm_command
- 如何在QT中关闭子窗口后执行功能
- 为什么尽管所有必需的功能都存在,但窗口始终不显示
- "PlaySound()"播放默认窗口错误声音的功能
- 链接失败。如何使用'NtQuerySystemTime'窗口功能?
- 在同一文件中实现多个窗口的功能
- 主功能和窗口,支持 Opengl 3.0+ 和 DirectX 10+
- OpenGL窗口的高效同步功能
- 如何获取窗口的命令行"打开方式.."功能?
- 问如何正确地做一个屏幕保护程序的功能窗口C++
- 当通过ShellExecuteEx功能启动时,安装屏蔽窗口没有出现在顶部