Search in sources :

Example 1 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testFileEncryptionStatus.

public void testFileEncryptionStatus() throws Exception {
    DWORDByReference lpStatus = new DWORDByReference();
    // create a temp file
    File file = createTempFile();
    String lpFileName = file.getAbsolutePath();
    // unencrypted file
    assertTrue(Advapi32.INSTANCE.FileEncryptionStatus(lpFileName, lpStatus));
    assertEquals(FILE_ENCRYPTABLE, lpStatus.getValue().intValue());
    // read only file
    file.setWritable(false);
    assertTrue(Advapi32.INSTANCE.FileEncryptionStatus(lpFileName, lpStatus));
    assertEquals(FILE_READ_ONLY, lpStatus.getValue().intValue());
    // encrypted file
    file.setWritable(true);
    assertTrue(Advapi32.INSTANCE.EncryptFile(lpFileName));
    assertTrue(Advapi32.INSTANCE.FileEncryptionStatus(lpFileName, lpStatus));
    assertEquals(FILE_IS_ENCRYPTED, lpStatus.getValue().intValue());
    file.delete();
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) File(java.io.File)

Example 2 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testMapGenericAllMask.

public void testMapGenericAllMask() {
    final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
    mapping.genericRead = new DWORD(FILE_GENERIC_READ);
    mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
    mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
    mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
    final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_ALL));
    Advapi32.INSTANCE.MapGenericMask(rights, mapping);
    assertEquals(FILE_ALL_ACCESS, rights.getValue().intValue());
    assertTrue(GENERIC_ALL != (rights.getValue().intValue() & GENERIC_ALL));
}
Also used : GENERIC_MAPPING(com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Example 3 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testEncryptionDisable.

public void testEncryptionDisable() throws Exception {
    DWORDByReference lpStatus = new DWORDByReference();
    // create a temp dir
    String filePath = System.getProperty("java.io.tmpdir") + File.separator + System.nanoTime();
    String DirPath = filePath;
    File dir = new File(filePath);
    dir.mkdir();
    // check status
    assertTrue(Advapi32.INSTANCE.FileEncryptionStatus(DirPath, lpStatus));
    assertEquals(FILE_ENCRYPTABLE, lpStatus.getValue().intValue());
    // disable encryption
    assertTrue(Advapi32.INSTANCE.EncryptionDisable(DirPath, true));
    assertTrue(Advapi32.INSTANCE.FileEncryptionStatus(DirPath, lpStatus));
    assertEquals(FILE_DIR_DISALOWED, lpStatus.getValue().intValue());
    // enable encryption
    assertTrue(Advapi32.INSTANCE.EncryptionDisable(DirPath, false));
    assertTrue(Advapi32.INSTANCE.FileEncryptionStatus(DirPath, lpStatus));
    assertEquals(FILE_ENCRYPTABLE, lpStatus.getValue().intValue());
    // clean up
    for (File file : dir.listFiles()) {
        file.delete();
    }
    dir.delete();
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) File(java.io.File)

Example 4 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class ITypeInfoTest method testGetDocumentation.

@Test
public void testGetDocumentation() {
    ITypeInfo[] typeInfos = getTypeInfos();
    MEMBERID memid = new MEMBERID(0);
    BSTRByReference pBstrName = new BSTRByReference();
    BSTRByReference pBstrDocString = new BSTRByReference();
    DWORDByReference pdwHelpContext = new DWORDByReference();
    BSTRByReference pBstrHelpFile = new BSTRByReference();
    for (ITypeInfo typeInfo : typeInfos) {
        HRESULT hr = typeInfo.GetDocumentation(memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
        if (COMUtils.SUCCEEDED(hr)) {
            //System.out.println("pBstrHelpFile: " + pBstrHelpFile.getValue());
            return;
        }
    }
    throw new RuntimeException("Didn't find documentation in any of the type infos");
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) MEMBERID(com.sun.jna.platform.win32.OaIdl.MEMBERID) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) BSTRByReference(com.sun.jna.platform.win32.WTypes.BSTRByReference) Test(org.junit.Test)

Example 5 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class User32Test method testSendMessageTimeout.

@Test
public void testSendMessageTimeout() {
    DesktopWindow explorerProc = getWindowByProcessPath("explorer.exe");
    assertNotNull(explorerProc);
    final DWORDByReference hIconNumber = new DWORDByReference();
    LRESULT result = User32.INSTANCE.SendMessageTimeout(explorerProc.getHWND(), WinUser.WM_GETICON, new WPARAM(WinUser.ICON_BIG), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber);
    assertNotEquals(0, result);
}
Also used : LRESULT(com.sun.jna.platform.win32.WinDef.LRESULT) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) LPARAM(com.sun.jna.platform.win32.WinDef.LPARAM) WPARAM(com.sun.jna.platform.win32.WinDef.WPARAM) DesktopWindow(com.sun.jna.platform.DesktopWindow) Test(org.junit.Test)

Aggregations

DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)34 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)12 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)11 Test (org.junit.Test)8 Memory (com.sun.jna.Memory)6 GENERIC_MAPPING (com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING)6 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)6 DdeCallback (com.sun.jna.platform.win32.Ddeml.DdeCallback)3 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)3 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)3 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)3 PVOID (com.sun.jna.platform.win32.WinDef.PVOID)3 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)3 Pointer (com.sun.jna.Pointer)2 IID (com.sun.jna.platform.win32.Guid.IID)2 REFIID (com.sun.jna.platform.win32.Guid.REFIID)2 MC_DRIVE_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_DRIVE_TYPE)2 MC_GAIN_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_GAIN_TYPE)2 MC_POSITION_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_POSITION_TYPE)2 MC_SIZE_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_SIZE_TYPE)2