winapi - How to call a kernel32.dll function GetTickCount() using LoadLibrary(..) in C++ -
i searching function time in milliseconds on windows machine. essentially, want call winapi function gettickcount(), i'm stuck on "use loadlibrary(...) n call gettickcount() function" part..
i searched every forum n googled everywhere people have used incomplete codes don't compile..can write short sample program load kernel32.dll , call gettickcount() display time in milliseconds?
please write code compiles!
you can't load kernel32.dll
, it's loaded every process. , gettickcount
exists on every version of windows, don't need getprocaddress
see if exists. need is:
#include <windows.h> #include <iostream> int main(void) { std::cout << gettickcount() << std::endl; }
a dynamic load example (since winmm.dll
not preloaded):
#include <windows.h> #include <iostream> int main(void) { hmodule winmmdll = loadlibrarya("winmm.dll"); if (!winmmdll) { std::cerr << "loadlibrary failed." << std::endl; return 1; } typedef dword (winapi *timegettime_fn)(void); timegettime_fn pfntimegettime = (timegettime_fn)getprocaddress(winmmdll, "timegettime"); if (!pfntimegettime) { std::cerr << "getprocaddress failed." << std::endl; return 2; } std::cout << (*pfntimegettime)() << std::endl; return 0; }
i've compiled , run example using visual studio 2010 command prompt, no special compiler or linker options needed.
Comments
Post a Comment