我在我的应用程序中尝试使用这个简单的代码来计算硬盘写入速度:
#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
documentation说没有关联的导入库,我必须使用 LoadLibrary()
和 GetProcAddress()
函数动态链接到 Ntdll.dll
。但我不明白如何使用这些功能。有人可以提供如何使用这些功能的代码示例吗?
最佳答案
这就是您使用此功能的方式。
HMODULE hNtDll = GetModuleHandleA("ntdll");
NTSTATUS (WINAPI *NtQuerySystemTime)(PLARGE_INTEGER) =
(NTSTATUS (WINAPI*)(PLARGE_INTEGER))GetProcAddress(hNtDll, "NtQuerySystemTime");
关于c++ - 链接失败。如何使用 'NtQuerySystemTime' windows函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19645648/