Search code examples
cwinapimingw32

Why the program collapsed when using FileTimeToSystemTime()?


I want to change FileTime to SystemTime, but the program always collapsed, WHY?

Thanks in advance.

FILETIME *Kernel_Time;
HANDLE Process = OpenProcess ( PROCESS_ALL_ACCESS, FALSE, 0);
GetProcessTimes (Process, NULL, NULL, Kernel_Time, NULL);
SYSTEMTIME  *Sys_Time;
FileTimeToSystemTime (Kernel_Time, Sys_Time);

Solution

  • You don't allocate memory for the result. It is probably easier to allocate it on the stack, and use the address in the function call like this:

    FILETIME Kernel_Time;
    HANDLE Process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 0);
    GetProcessTimes(Process, NULL, NULL, &Kernel_Time, NULL);
    SYSTEMTIME Sys_Time;
    FileTimeToSystemTime(&Kernel_Time, &Sys_Time);