Skip to content

Commit

Permalink
Correct typemapper used for structures defined
Browse files Browse the repository at this point in the history
Winnetwk definitions follow the typemapper set by the "w32.ascii"
property, following the convention demonstrated/used in 
W32APIOptions.DEFAULT.

The definitions in LMShare are defined as pure UNICODE.

Closes: java-native-access#668
  • Loading branch information
matthiasblaesing committed Jul 26, 2016
1 parent c3cb85a commit 60531d9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Bug Fixes
* [#674](https://github.com/java-native-access/jna/pull/674): Update references to Apache License as requested by issue #673 [@bhamail](https://github.com/bhamail)
* [#636](https://github.com/java-native-access/jna/issues/636): Staticly link visual c++ runtime when building with MSVC - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#624](https://github.com/java-native-access/jna/issues/624): WinDef.DWORD getLow() & getHigh() using incorrect bit mask - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#668](https://github.com/java-native-access/jna/issues/668): Correct typemapper used for structures defined in `com.sun.jna.platform.win32.LMShare` and `com.sun.jna.platform.win32.Winnetwk` - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 4.2.1
=============
Expand Down
9 changes: 5 additions & 4 deletions contrib/platform/src/com/sun/jna/platform/win32/LMShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.win32.W32APITypeMapper;

/**
* Ported from LMShare.h.
Expand Down Expand Up @@ -118,11 +119,11 @@ public static class SHARE_INFO_2 extends Structure {
public String shi2_passwd;

public SHARE_INFO_2() {
super();
super(W32APITypeMapper.UNICODE);
}

public SHARE_INFO_2(Pointer memory) {
super(memory);
super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE);
read();
}

Expand Down Expand Up @@ -202,11 +203,11 @@ public static class SHARE_INFO_502 extends Structure {
public Pointer shi502_security_descriptor;

public SHARE_INFO_502() {
super();
super(W32APITypeMapper.UNICODE);
}

public SHARE_INFO_502(Pointer memory) {
super(memory);
super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE);
read();
}

Expand Down
13 changes: 7 additions & 6 deletions contrib/platform/src/com/sun/jna/platform/win32/Winnetwk.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.win32.W32APITypeMapper;

/**
* Ported from AccCtrl.h. Microsoft Windows SDK 7.1
Expand Down Expand Up @@ -346,11 +347,11 @@ public ByReference(Pointer memory) {
public String lpProvider;

public NETRESOURCE() {
super();
super(W32APITypeMapper.DEFAULT);
}

public NETRESOURCE(Pointer address) {
super(address);
super(address, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT);
read();
}

Expand Down Expand Up @@ -391,11 +392,11 @@ public ByReference(Pointer memory) {
public String lpUniversalName;

public UNIVERSAL_NAME_INFO() {
super();
super(W32APITypeMapper.DEFAULT);
}

public UNIVERSAL_NAME_INFO(Pointer address) {
super(address);
super(address, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT);
read();
}

Expand Down Expand Up @@ -444,11 +445,11 @@ public ByReference(Pointer memory) {
public String lpRemainingPath;

public REMOTE_NAME_INFO() {
super();
super(W32APITypeMapper.DEFAULT);
}

public REMOTE_NAME_INFO(Pointer address) {
super(address);
super(address, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT);
read();
}

Expand Down
15 changes: 11 additions & 4 deletions contrib/platform/test/com/sun/jna/platform/win32/MprTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public static void main(String[] args) throws Exception {
junit.textui.TestRunner.run(MprTest.class);
}

public void testCreateLocalShare() throws Exception {
File fileShareFolder = createTempFolder();
String share = createLocalShare(fileShareFolder);
Netapi32.INSTANCE.NetShareDel(null, share, 0);
}

public void testWNetUseConnection() throws Exception {
// First create a share on the local machine
File fileShareFolder = createTempFolder();
Expand Down Expand Up @@ -262,10 +268,11 @@ private String createLocalShare(File shareFolder) throws Exception {
shi.write();

IntByReference parm_err = new IntByReference(0);
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetShareAdd(null, // Use
// local
// computer
2, shi.getPointer(), parm_err));
int errorCode = Netapi32.INSTANCE.NetShareAdd(null, // Use local computer
2, shi.getPointer(), parm_err);
assertEquals(
String.format("Failed to create share - errorCode: %d (Param: %d)", errorCode, parm_err.getValue()),
LMErr.NERR_Success, errorCode);

return shareFolder.getName();
}
Expand Down
5 changes: 4 additions & 1 deletion src/com/sun/jna/win32/W32APITypeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
* @author twall
*/
public class W32APITypeMapper extends DefaultTypeMapper {

/** Standard TypeMapper to use the unicode version of a w32 API. */
public static final TypeMapper UNICODE = new W32APITypeMapper(true);
/** Standard TypeMapper to use the ASCII/MBCS version of a w32 API. */
public static final TypeMapper ASCII = new W32APITypeMapper(false);
/** Default TypeMapper to use - depends on the value of {@code w32.ascii} system property */
public static final TypeMapper DEFAULT = Boolean.getBoolean("w32.ascii") ? ASCII : UNICODE;

protected W32APITypeMapper(boolean unicode) {
if (unicode) {
Expand Down

0 comments on commit 60531d9

Please sign in to comment.