From d84f5e00ccd9735a781b891c44133f4e4270f49c Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Fri, 16 Aug 2019 15:06:27 -0700 Subject: [PATCH 1/2] Add failing test for IShellFolder#ParseDisplayName --- .../platform/win32/COM/IShellFolderTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/IShellFolderTest.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/IShellFolderTest.java index 99df41ea25..24b2467bad 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/COM/IShellFolderTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/IShellFolderTest.java @@ -27,13 +27,19 @@ */ import com.sun.jna.Pointer; -import junit.framework.TestCase; - -import com.sun.jna.platform.win32.*; +import com.sun.jna.platform.win32.Guid; import com.sun.jna.platform.win32.Guid.REFIID; +import com.sun.jna.platform.win32.Ole32; import com.sun.jna.platform.win32.ShTypes.STRRET; +import com.sun.jna.platform.win32.Shell32; +import com.sun.jna.platform.win32.ShlObj; +import com.sun.jna.platform.win32.Shlwapi; +import com.sun.jna.platform.win32.WinNT; +import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; +import junit.framework.TestCase; + public class IShellFolderTest extends TestCase { static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); @@ -102,4 +108,20 @@ public void testEnumObjects() throws Exception { peidl.Release(); assertTrue(sawNames); // We should see at least one item with a name } + + public void testParseDisplayName() throws Exception { + String directory = System.getenv("WinDir"); + + IntByReference pchEaten = new IntByReference(); + PointerByReference ppidl = new PointerByReference(); + IntByReference pdwAttributes = new IntByReference(); + PointerByReference desktopFolder = new PointerByReference(); + + WinNT.HRESULT hResult = Shell32.INSTANCE.SHGetDesktopFolder(desktopFolder); + assertEquals(COMUtils.S_OK, hResult.intValue()); + + IShellFolder shellFolder = IShellFolder.Converter.PointerToIShellFolder(desktopFolder); + hResult = shellFolder.ParseDisplayName(null, null, directory, pchEaten, ppidl, pdwAttributes); + assertEquals(COMUtils.S_OK, hResult.intValue()); + } } \ No newline at end of file From 28da1fb7f9e7bf7b2898a459f3a93e3f9d8e081a Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Fri, 16 Aug 2019 15:30:22 -0700 Subject: [PATCH 2/2] Fixed the bug, tests now pass! --- CHANGES.md | 1 + .../src/com/sun/jna/platform/win32/COM/IShellFolder.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a154b39431..362a7fd1ff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Features Bug Fixes --------- * [#1115](https://github.com/java-native-access/jna/issues/1115): Fix signature for `c.s.j.p.win32.Kernel32#CreateRemoteThread` and bind `VirtualAllocEx`, `VirtualFreeEx`, `GetExitCodeThread` in `c.s.j.p.win32.Kernel32` - [@apangin](https://github.com/apangin), [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#1127](https://github.com/java-native-access/jna/issues/1127): Windows needs a wide string in `c.s.j.p.win32.COM.IShellFolder#ParseDisplayName` - [@dbwiddis](https://github.com/dbwiddis). Release 5.4.0 ============= diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/IShellFolder.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/IShellFolder.java index fe7f03f59f..61d5b19115 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/IShellFolder.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/IShellFolder.java @@ -27,6 +27,7 @@ */ import com.sun.jna.Function; +import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.platform.win32.Guid.IID; import com.sun.jna.platform.win32.Guid.REFIID; @@ -480,7 +481,11 @@ public int Release() { @Override public WinNT.HRESULT ParseDisplayName(WinDef.HWND hwnd, Pointer pbc, String pszDisplayName, IntByReference pchEaten, PointerByReference ppidl, IntByReference pdwAttributes) { Function f = Function.getFunction(vTable[3], Function.ALT_CONVENTION); - return new WinNT.HRESULT(f.invokeInt(new Object[]{interfacePointer, hwnd, pbc, pszDisplayName, pchEaten, ppidl, pdwAttributes})); + // pszDisplayName is mapped as String but Windows needs + // Wide String. Convert and pass here. + char[] pszDisplayNameNative = Native.toCharArray(pszDisplayName); + return new WinNT.HRESULT(f.invokeInt(new Object[] { interfacePointer, hwnd, pbc, + pszDisplayNameNative, pchEaten, ppidl, pdwAttributes })); } @Override