CPU Process time using GetProcessTimes and FileTimeToSystemTime do not work in 64 bit win

这一生的挚爱 提交于 2019-12-12 05:08:52

问题


I am trying to measure CPU time. It works great on Win 32, but on 64 bit, it says:

error LNK2019: unresolved external symbol __imp_GetProcessTimes referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ) 

It has similar error for FileTimeToSystemTime

error LNK2019: unresolved external symbol __imp_FileTimeToSystemTime referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ)

Function itself is not that important there is no issue with it.
Are this calls legit in 64 bit architecture or what?

This is not the only issue it seems like its not linking correctly to libraries on 64 bit windows.
Is there a setting I should set for it to link properly?


回答1:


Do you're build settings for the two environments have the same import libraries listed. Both of those functions are in kernel32.dll.




回答2:


Check your linker flags. The entire project configuration for 64-bit builds is different from that of 32-bit builds. So check your project settings to verify that they both link to the same libraries.

Also check that the compiler and linker got invoked correctly, either by checking the Command Line panes in project settings, or by inspecting the build log.

I just tried creating a 64-bit build of this code in Visual Studio 2010, and it worked fine:

#include <Windows.h>

int CALLBACK WinMain(
  __in  HINSTANCE hInstance,
  __in  HINSTANCE hPrevInstance,
  __in  LPSTR lpCmdLine,
  __in  int nCmdShow
) {
  FILETIME ct;
  FILETIME et;
  FILETIME kt;
  FILETIME ut;
  GetProcessTimes(NULL, &ct, &et, &kt, &ut);

  SYSTEMTIME st;
  FileTimeToSystemTime(&ut, &st);

}

I simply created a new Win32 project, added a 64-bit platform, and compiled. I didn't change any project settings at all.




回答3:


The documentation for GetProcessTimes and FileTimeToSystemTime will tell you the headers to include, AND the library file to link to as well. However, Visual studio will usually link those in for you automatically. Do you have ignore default libraries checked perhaps in your project?



来源:https://stackoverflow.com/questions/3071652/cpu-process-time-using-getprocesstimes-and-filetimetosystemtime-do-not-work-in-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!