Search in sources :

Example 1 with FILETIME

use of com.sun.jna.platform.win32.WinBase.FILETIME in project jna by java-native-access.

the class WinBaseTest method testFiletime.

public void testFiletime() {
    // subtract to convert ms after 1/1/1970 to ms after 1/1/1601
    long epochDiff = 11644473600000L;
    // Construct filetimes for ms after 1/1/1601, check for 100-ns after
    assertEquals("Mismatched filetime for 2ms", (new FILETIME(new Date(2L - epochDiff))).toDWordLong().longValue(), 2L * 10000);
    assertEquals("Mismatched filetime for 2^16ms", (new FILETIME(new Date((1L << 16) - epochDiff))).toDWordLong().longValue(), (1L << 16) * 10000);
    assertEquals("Mismatched filetime for 2^32ms", (new FILETIME(new Date((1L << 32) - epochDiff))).toDWordLong().longValue(), (1L << 32) * 10000);
    assertEquals("Mismatched filetime for 2^49ms", (new FILETIME(new Date((1L << 49) - epochDiff))).toDWordLong().longValue(), (1L << 49) * 10000);
}
Also used : FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME) Date(java.util.Date)

Example 2 with FILETIME

use of com.sun.jna.platform.win32.WinBase.FILETIME in project jna by java-native-access.

the class Win32SpoolMonitor method printJobInfo.

private void printJobInfo(JOB_INFO_1 jobInfo1) {
    FILETIME lpFileTime = new FILETIME();
    Kernel32.INSTANCE.SystemTimeToFileTime(jobInfo1.Submitted, lpFileTime);
    String info = "JobId: " + jobInfo1.JobId + "\n" + "pDatatype: " + jobInfo1.pDatatype + "\n" + "PagesPrinted: " + jobInfo1.PagesPrinted + "\n" + "pDocument: " + jobInfo1.pDocument + "\n" + "pMachineName: " + jobInfo1.pMachineName + "\n" + "Position: " + jobInfo1.Position + "\n" + "pPrinterName: " + jobInfo1.pPrinterName + "\n" + "Priority: " + jobInfo1.Priority + "\n" + "pStatus: " + jobInfo1.pStatus + "\n" + "pUserName: " + jobInfo1.pUserName + "\n" + "Status: " + jobInfo1.Status + "\n" + "TotalPages: " + jobInfo1.TotalPages + "\n" + "Submitted: " + DateFormat.getDateTimeInstance().format(lpFileTime.toDate());
    System.out.println(info);
}
Also used : FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME)

Example 3 with FILETIME

use of com.sun.jna.platform.win32.WinBase.FILETIME in project jna by java-native-access.

the class Kernel32Test method testFileTimeFromLargeInteger.

/**
     * Test FILETIME's LARGE_INTEGER constructor
     * @throws IOException
     */
public final void testFileTimeFromLargeInteger() throws IOException {
    File tmp = File.createTempFile("testGetFileInformationByHandleEx", "jna");
    tmp.deleteOnExit();
    HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_WRITE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
    assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
    try {
        Memory p = new Memory(FILE_BASIC_INFO.sizeOf());
        if (false == Kernel32.INSTANCE.GetFileInformationByHandleEx(hFile, WinBase.FileBasicInfo, p, new DWORD(p.size()))) {
            fail("GetFileInformationByHandleEx failed with " + Kernel32.INSTANCE.GetLastError());
        }
        FILE_BASIC_INFO fbi = new FILE_BASIC_INFO(p);
        FILETIME ft = new FILETIME(fbi.LastWriteTime);
        SYSTEMTIME stUTC = new SYSTEMTIME();
        SYSTEMTIME stLocal = new SYSTEMTIME();
        Kernel32.INSTANCE.FileTimeToSystemTime(ft, stUTC);
        // Covert to local
        Kernel32.INSTANCE.SystemTimeToTzSpecificLocalTime(null, stUTC, stLocal);
        FileTime calculatedCreateTime = FileTime.fromMillis(stLocal.toCalendar().getTimeInMillis());
        // Actual file's createTime
        FileTime createTime = Files.getLastModifiedTime(Paths.get(tmp.getAbsolutePath()));
        assertEquals(createTime.toMillis(), calculatedCreateTime.toMillis());
    } finally {
        Kernel32.INSTANCE.CloseHandle(hFile);
    }
}
Also used : FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME) Memory(com.sun.jna.Memory) SYSTEMTIME(com.sun.jna.platform.win32.WinBase.SYSTEMTIME) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) FileTime(java.nio.file.attribute.FileTime) File(java.io.File) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) FILE_BASIC_INFO(com.sun.jna.platform.win32.WinBase.FILE_BASIC_INFO)

Example 4 with FILETIME

use of com.sun.jna.platform.win32.WinBase.FILETIME in project jna by java-native-access.

the class RunningObjectTable method NoteChangeTime.

@Override
public HRESULT NoteChangeTime(DWORD dwRegister, FILETIME pfiletime) {
    final int vTableId = 7;
    WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), dwRegister, pfiletime }, WinNT.HRESULT.class);
    return hr;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) WinNT(com.sun.jna.platform.win32.WinNT) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT)

Example 5 with FILETIME

use of com.sun.jna.platform.win32.WinBase.FILETIME in project jna by java-native-access.

the class Kernel32Test method testSystemTimeToFileTimeAndFileTimeToSystemTime.

/**
     * Test both SystemTimeToFileTime and FileTimeToSystemTime
     * @throws IOException
     */
public final void testSystemTimeToFileTimeAndFileTimeToSystemTime() throws IOException {
    WinBase.SYSTEMTIME systemTime = new WinBase.SYSTEMTIME();
    Kernel32.INSTANCE.GetSystemTime(systemTime);
    WinBase.FILETIME fileTime = new WinBase.FILETIME();
    if (false == Kernel32.INSTANCE.SystemTimeToFileTime(systemTime, fileTime)) {
        fail("SystemTimeToFileTime failed with " + Kernel32.INSTANCE.GetLastError());
    }
    WinBase.SYSTEMTIME newSystemTime = new WinBase.SYSTEMTIME();
    if (false == Kernel32.INSTANCE.FileTimeToSystemTime(fileTime, newSystemTime)) {
        fail("FileTimeToSystemTime failed with " + Kernel32.INSTANCE.GetLastError());
    }
    assertEquals(systemTime.wYear, newSystemTime.wYear);
    assertEquals(systemTime.wDay, newSystemTime.wDay);
    assertEquals(systemTime.wMonth, newSystemTime.wMonth);
    assertEquals(systemTime.wHour, newSystemTime.wHour);
    assertEquals(systemTime.wMinute, newSystemTime.wMinute);
    assertEquals(systemTime.wSecond, newSystemTime.wSecond);
    assertEquals(systemTime.wMilliseconds, newSystemTime.wMilliseconds);
}
Also used : SYSTEMTIME(com.sun.jna.platform.win32.WinBase.SYSTEMTIME) FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME) SYSTEMTIME(com.sun.jna.platform.win32.WinBase.SYSTEMTIME) FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME)

Aggregations

FILETIME (com.sun.jna.platform.win32.WinBase.FILETIME)6 SYSTEMTIME (com.sun.jna.platform.win32.WinBase.SYSTEMTIME)2 Memory (com.sun.jna.Memory)1 FILE_BASIC_INFO (com.sun.jna.platform.win32.WinBase.FILE_BASIC_INFO)1 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)1 WinNT (com.sun.jna.platform.win32.WinNT)1 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)1 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)1 IntByReference (com.sun.jna.ptr.IntByReference)1 File (java.io.File)1 FileTime (java.nio.file.attribute.FileTime)1 Date (java.util.Date)1