user1978386 user1978386 - 1 year ago 140
C++ Question

Linking failure. How to use 'NtQuerySystemTime' windows function?

I try this simple code to calculate HDD write speed in my application:

#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);


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) ;

but it fails to link.

On MSDN, the
says there is no associated import library and that I must use the
functions to dynamically link to
. But I don't understand how to use those functions. Can someone please provide a code example of how to use those functions?

Answer Source

This is how you would be able to use this function.

HMODULE hNtDll = GetModuleHandleA("ntdll");
    (NTSTATUS (WINAPI*)(PLARGE_INTEGER))GetProcAddress(hNtDll, "NtQuerySystemTime");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download