Search in sources :

Example 1 with REMOTE_NAME_INFO

use of com.sun.jna.platform.win32.Winnetwk.REMOTE_NAME_INFO in project jna by java-native-access.

the class MprTest method testWNetGetUniversalName.

public void testWNetGetUniversalName() throws Exception {
    // MSDN recommends this as a reasonable size
    int bufferSize = 1024;
    Memory memory = new Memory(bufferSize);
    IntByReference lpBufferSize = new IntByReference(bufferSize);
    File file = null;
    String share = null;
    String driveLetter = new String("x:");
    File fileShareFolder = createTempFolder();
    try {
        // Create a local share and connect to it.
        share = createLocalShare(fileShareFolder);
        // Connect to share using a drive letter.
        connectToLocalShare(share, driveLetter);
        // Create a path on local device redirected to the share.
        String filePath = new String(driveLetter + "\\testfile.txt");
        file = new File(filePath);
        file.createNewFile();
        // Test WNetGetUniversalName using UNIVERSAL_NAME_INFO_LEVEL
        assertEquals(WinError.ERROR_SUCCESS, Mpr.INSTANCE.WNetGetUniversalName(filePath, Winnetwk.UNIVERSAL_NAME_INFO_LEVEL, memory, lpBufferSize));
        UNIVERSAL_NAME_INFO uinfo = new UNIVERSAL_NAME_INFO(memory);
        assertNotNull(uinfo.lpUniversalName);
        // Test WNetGetUniversalName using REMOTE_NAME_INFO_LEVEL
        assertEquals(WinError.ERROR_SUCCESS, Mpr.INSTANCE.WNetGetUniversalName(filePath, Winnetwk.REMOTE_NAME_INFO_LEVEL, memory, lpBufferSize));
        REMOTE_NAME_INFO rinfo = new REMOTE_NAME_INFO(memory);
        assertNotNull(rinfo.lpUniversalName);
        assertNotNull(rinfo.lpConnectionName);
        assertNotNull(rinfo.lpRemainingPath);
    } finally {
        // Clean up resources
        if (file != null)
            file.delete();
        if (share != null) {
            disconnectFromLocalShare(driveLetter);
            deleteLocalShare(share);
            fileShareFolder.delete();
        }
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) REMOTE_NAME_INFO(com.sun.jna.platform.win32.Winnetwk.REMOTE_NAME_INFO) UNIVERSAL_NAME_INFO(com.sun.jna.platform.win32.Winnetwk.UNIVERSAL_NAME_INFO) File(java.io.File)

Aggregations

Memory (com.sun.jna.Memory)1 REMOTE_NAME_INFO (com.sun.jna.platform.win32.Winnetwk.REMOTE_NAME_INFO)1 UNIVERSAL_NAME_INFO (com.sun.jna.platform.win32.Winnetwk.UNIVERSAL_NAME_INFO)1 IntByReference (com.sun.jna.ptr.IntByReference)1 File (java.io.File)1