Skip to content

Commit

Permalink
Merge pull request #1012 from matthiasblaesing/jna-1010
Browse files Browse the repository at this point in the history
[#1010] Fix binding of `lpAccessName` parameter of `c.s.j.p.win32.Mpr#WNetUseConnection
  • Loading branch information
matthiasblaesing committed Sep 11, 2018
2 parents 08b496f + 0a0c380 commit a4fcfae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Bug Fixes
</ol> - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#958](https://github.com/java-native-access/jna/issues/958): Update for PR 863: Old toolchains produce binaries without hard-/softfloat markers. Rasbian is missinng the markers and the oracle JDK is also affected. For hardfloat detection now also the Arm EABI section is also considered - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#974](https://github.com/java-native-access/jna/issues/974): If the callback code failed to attach to the JVM, this lead to a segfault. The success of attaching to the JVM was checked to late and an invalid `JNIEnv` pointer was used to access the JVM - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#1010](https://github.com/java-native-access/jna/issues/1010): Fix binding of `lpAccessName` parameter of `com.sun.jna.platform.win32.Mpr#WNetUseConnection`

Breaking Changes
----------------
Expand Down
3 changes: 1 addition & 2 deletions contrib/platform/src/com/sun/jna/platform/win32/Mpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
import com.sun.jna.platform.win32.Winnetwk.*;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

Expand Down Expand Up @@ -308,7 +307,7 @@ public interface Mpr extends StdCallLibrary {
* (v=vs.85).aspx
*/
public int WNetUseConnection(HWND hwndOwner, NETRESOURCE lpNETRESOURCE, String lpPassword, String lpUserID, int dwFlags,
PointerByReference lpAccessName, IntByReference lpBufferSize, IntByReference lpResult);
Pointer lpAccessName, IntByReference lpBufferSize, IntByReference lpResult);

/**
* The WNetAddConnection3 function makes a connection to a network resource.
Expand Down
22 changes: 21 additions & 1 deletion contrib/platform/test/com/sun/jna/platform/win32/MprTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;

import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.LMShare.SHARE_INFO_2;
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
import com.sun.jna.platform.win32.Winnetwk.ConnectFlag;
Expand All @@ -27,6 +28,8 @@
import com.sun.jna.platform.win32.Winnetwk.RESOURCEUSAGE;
import com.sun.jna.platform.win32.Winnetwk.UNIVERSAL_NAME_INFO;
import com.sun.jna.ptr.IntByReference;
import static com.sun.jna.win32.W32APIOptions.DEFAULT_OPTIONS;
import static com.sun.jna.win32.W32APIOptions.UNICODE_OPTIONS;

import junit.framework.TestCase;

Expand Down Expand Up @@ -61,7 +64,24 @@ public void testWNetUseConnection() throws Exception {
// Cancel any existing connections of the same name
Mpr.INSTANCE.WNetCancelConnection2(resource.lpRemoteName, 0, true);
// Establish a new one
assertEquals(WinError.ERROR_SUCCESS, Mpr.INSTANCE.WNetUseConnection(null, resource, null, null, 0, null, null, null));
Memory lpAccessName;
if(DEFAULT_OPTIONS==UNICODE_OPTIONS) {
lpAccessName = new Memory((WinDef.MAX_PATH + 1) * Native.WCHAR_SIZE);
} else {
lpAccessName = new Memory(WinDef.MAX_PATH + 1);
}
IntByReference lpAccessNameSize = new IntByReference(WinDef.MAX_PATH);
assertEquals(WinError.ERROR_SUCCESS, Mpr.INSTANCE.WNetUseConnection(null, resource, null, null, 0, lpAccessName, lpAccessNameSize, null));
String accessName;
if(DEFAULT_OPTIONS==UNICODE_OPTIONS) {
accessName = lpAccessName.getWideString(0);
} else {
accessName = lpAccessName.getString(0);
}
// System.out.println("Size: " + lpAccessNameSize.getValue());
// System.out.println("lpAccessName: " + accessName);
assertNotNull(accessName);
assertFalse(accessName.isEmpty());
} finally {
// Clean up resources
Mpr.INSTANCE.WNetCancelConnection2(resource.lpRemoteName, 0, true);
Expand Down

0 comments on commit a4fcfae

Please sign in to comment.