From ab84488d4e14ba7bd3f6a1ed7930b46ccfe94af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Tue, 26 Jul 2016 23:05:48 +0200 Subject: [PATCH] Correct typemapper used for structures defined 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: #668 --- CHANGES.md | 1 + .../com/sun/jna/platform/win32/DsGetDC.java | 9 ++-- .../com/sun/jna/platform/win32/LMAccess.java | 45 ++++++++++--------- .../com/sun/jna/platform/win32/LMShare.java | 9 ++-- .../src/com/sun/jna/platform/win32/Sspi.java | 6 +++ .../com/sun/jna/platform/win32/WinBase.java | 6 +++ .../com/sun/jna/platform/win32/WinCrypt.java | 5 ++- .../com/sun/jna/platform/win32/WinUser.java | 4 +- .../com/sun/jna/platform/win32/Winnetwk.java | 13 +++--- .../com/sun/jna/platform/win32/Winsvc.java | 1 - .../com/sun/jna/platform/win32/MprTest.java | 15 +++++-- src/com/sun/jna/win32/W32APITypeMapper.java | 5 ++- 12 files changed, 74 insertions(+), 45 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1e01d5b4aa..8407152047 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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.DsGetDC`, `com.sun.jna.platform.win32.LMAccess`, `com.sun.jna.platform.win32.LMShare`, `com.sun.jna.platform.win32.Sspi`, `com.sun.jna.platform.win32.WinBase`, `com.sun.jna.platform.win32.WinCrypt`, `com.sun.jna.platform.win32.WinUser` and `com.sun.jna.platform.win32.Winnetwk` - [@matthiasblaesing](https://github.com/matthiasblaesing). Release 4.2.1 ============= diff --git a/contrib/platform/src/com/sun/jna/platform/win32/DsGetDC.java b/contrib/platform/src/com/sun/jna/platform/win32/DsGetDC.java index cb2836abc1..a979b417b4 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/DsGetDC.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/DsGetDC.java @@ -18,6 +18,7 @@ import com.sun.jna.Structure; import com.sun.jna.platform.win32.Guid.GUID; import com.sun.jna.platform.win32.WinNT.PSID; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from DsGetDC.h. Windows SDK 6.0a @@ -107,11 +108,11 @@ public static class ByReference extends DOMAIN_CONTROLLER_INFO public String ClientSiteName; public DOMAIN_CONTROLLER_INFO() { - super(); + super(W32APITypeMapper.DEFAULT); } public DOMAIN_CONTROLLER_INFO(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT); read(); } @@ -235,11 +236,11 @@ protected List getFieldOrder() { } public DS_DOMAIN_TRUSTS() { - super(); + super(W32APITypeMapper.DEFAULT); } public DS_DOMAIN_TRUSTS(Pointer p) { - super(p); + super(p, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT); read(); } }; diff --git a/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java b/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java index e0eb6aee36..dcaacf00e4 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/LMAccess.java @@ -17,6 +17,7 @@ import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.platform.win32.WinNT.PSID; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from LMAccess.h. @@ -31,11 +32,11 @@ public static class LOCALGROUP_INFO_0 extends Structure { public String lgrui0_name; public LOCALGROUP_INFO_0() { - super(); + super(W32APITypeMapper.UNICODE); } public LOCALGROUP_INFO_0(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -52,11 +53,11 @@ public static class LOCALGROUP_INFO_1 extends Structure { public String lgrui1_comment; public LOCALGROUP_INFO_1() { - super(); + super(W32APITypeMapper.UNICODE); } public LOCALGROUP_INFO_1(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -88,11 +89,11 @@ public static class USER_INFO_0 extends Structure { public String usri0_name; public USER_INFO_0() { - super(); + super(W32APITypeMapper.UNICODE); } public USER_INFO_0(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -153,11 +154,11 @@ public static class USER_INFO_1 extends Structure { public String usri1_script_path; public USER_INFO_1() { - super(); + super(W32APITypeMapper.UNICODE); } public USER_INFO_1(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -232,11 +233,11 @@ public static class USER_INFO_23 extends Structure { public PSID.ByReference usri23_user_sid; public USER_INFO_23() { - super(); + super(W32APITypeMapper.UNICODE); } public USER_INFO_23(Pointer memory) { - useMemory(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -257,11 +258,11 @@ public static class GROUP_USERS_INFO_0 extends Structure { public String grui0_name; public GROUP_USERS_INFO_0() { - super(); + super(W32APITypeMapper.UNICODE); } public GROUP_USERS_INFO_0(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -282,11 +283,11 @@ public static class LOCALGROUP_USERS_INFO_0 extends Structure { public String lgrui0_name; public LOCALGROUP_USERS_INFO_0() { - super(); + super(W32APITypeMapper.UNICODE); } public LOCALGROUP_USERS_INFO_0(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -311,11 +312,11 @@ public static class GROUP_INFO_0 extends Structure { public String grpi0_name; public GROUP_INFO_0() { - super(); + super(W32APITypeMapper.UNICODE); } public GROUP_INFO_0(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -345,11 +346,11 @@ public static class GROUP_INFO_1 extends Structure { public String grpi1_comment; public GROUP_INFO_1() { - super(); + super(W32APITypeMapper.UNICODE); } public GROUP_INFO_1(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -390,11 +391,11 @@ public static class GROUP_INFO_2 extends Structure { public int grpi2_attributes; public GROUP_INFO_2() { - super(); + super(W32APITypeMapper.UNICODE); } public GROUP_INFO_2(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } @@ -435,11 +436,11 @@ public static class GROUP_INFO_3 extends Structure { public int grpi3_attributes; public GROUP_INFO_3() { - super(); + super(W32APITypeMapper.UNICODE); } public GROUP_INFO_3(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE); read(); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/LMShare.java b/contrib/platform/src/com/sun/jna/platform/win32/LMShare.java index 650b3f61c6..72b03a3e9b 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/LMShare.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/LMShare.java @@ -16,6 +16,7 @@ import com.sun.jna.Pointer; import com.sun.jna.Structure; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from LMShare.h. @@ -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(); } @@ -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(); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Sspi.java b/contrib/platform/src/com/sun/jna/platform/win32/Sspi.java index be8ea16902..3ed3cb7e4b 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Sspi.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Sspi.java @@ -17,6 +17,8 @@ import com.sun.jna.Memory; import com.sun.jna.Pointer; import com.sun.jna.Structure; +import com.sun.jna.TypeMapper; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from Sspi.h. @@ -450,6 +452,10 @@ public static class ByReference extends SecPkgInfo implements Structure.ByRefere */ public String Comment; + public SecPkgInfo() { + super(W32APITypeMapper.DEFAULT); + } + @Override protected List getFieldOrder() { return FIELDS; diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java b/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java index 7d78ed6800..51a800916c 100755 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java @@ -26,6 +26,7 @@ import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.ByteByReference; import com.sun.jna.win32.StdCallLibrary.StdCallCallback; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from Winbase.h (kernel32.dll/kernel services). @@ -427,6 +428,10 @@ public static class TIME_ZONE_INFORMATION extends Structure { public SYSTEMTIME DaylightDate; public LONG DaylightBias; + public TIME_ZONE_INFORMATION() { + super(W32APITypeMapper.DEFAULT); + } + @Override protected List getFieldOrder() { return Arrays.asList(new String[] { "Bias", "StandardName", "StandardDate", "StandardBias", "DaylightName", "DaylightDate", "DaylightBias" }); @@ -902,6 +907,7 @@ protected List getFieldOrder() { } public STARTUPINFO() { + super(W32APITypeMapper.DEFAULT); cb = new DWORD(size()); } } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinCrypt.java b/contrib/platform/src/com/sun/jna/platform/win32/WinCrypt.java index ba241dd0b8..499d43bd64 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinCrypt.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinCrypt.java @@ -19,6 +19,7 @@ import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.platform.win32.WinDef.HWND; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from WinCrypt.h. @@ -101,11 +102,11 @@ public static class CRYPTPROTECT_PROMPTSTRUCT extends Structure { public String szPrompt; public CRYPTPROTECT_PROMPTSTRUCT() { - super(); + super(W32APITypeMapper.DEFAULT); } public CRYPTPROTECT_PROMPTSTRUCT(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT); read(); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java b/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java index 36ab452206..e827d71ac5 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinUser.java @@ -22,6 +22,7 @@ import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR; import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.win32.StdCallLibrary.StdCallCallback; +import com.sun.jna.win32.W32APITypeMapper; /** * Ported from WinUser.h Microsoft Windows SDK 6.0A. @@ -1166,6 +1167,7 @@ public static class ByReference extends WNDCLASSEX implements * Instantiates a new wndclassex. */ public WNDCLASSEX() { + super(W32APITypeMapper.DEFAULT); } /** @@ -1175,7 +1177,7 @@ public WNDCLASSEX() { * the memory */ public WNDCLASSEX(Pointer memory) { - super(memory); + super(memory, Structure.ALIGN_DEFAULT, W32APITypeMapper.DEFAULT); read(); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Winnetwk.java b/contrib/platform/src/com/sun/jna/platform/win32/Winnetwk.java index 5a37ca6ede..5efce2e0e3 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Winnetwk.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Winnetwk.java @@ -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 @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Winsvc.java b/contrib/platform/src/com/sun/jna/platform/win32/Winsvc.java index e93481cafb..dcccc6409c 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Winsvc.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Winsvc.java @@ -18,7 +18,6 @@ import com.sun.jna.Memory; import com.sun.jna.Pointer; import com.sun.jna.Structure; -import com.sun.jna.TypeMapper; import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.win32.W32APITypeMapper; diff --git a/contrib/platform/test/com/sun/jna/platform/win32/MprTest.java b/contrib/platform/test/com/sun/jna/platform/win32/MprTest.java index c174136911..869eaf096c 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/MprTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/MprTest.java @@ -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(); @@ -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(); } diff --git a/src/com/sun/jna/win32/W32APITypeMapper.java b/src/com/sun/jna/win32/W32APITypeMapper.java index 98d193c18a..63b3e0dc2e 100644 --- a/src/com/sun/jna/win32/W32APITypeMapper.java +++ b/src/com/sun/jna/win32/W32APITypeMapper.java @@ -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) {