-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IShellFolder support #524
Merged
twall
merged 12 commits into
java-native-access:master
from
lwahonen:IShellFolder_support
Dec 4, 2015
Merged
IShellFolder support #524
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1061c1a
Make sure the Structure constructors are always chained in, so QueryI…
1d47c7e
Needed function to get My Computer shell object from Shell32
0fb7724
Shlwapi wrapper
fa24e9d
Necessary interfaces for enumerating items in My Computer
931cf53
An example into how to use the interfaces and functions in this pull …
8fe5251
Added assertions for COM success status
218271b
Clarified changes.md
e792f2f
Added documentation
7bd556e
Copyright notice replaced with a author tag
d81cf89
Add documentation to IEnumIDList
e24f188
Document the IUnknown methods too
0ab0660
Documentation for IShellFolder too
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
contrib/platform/src/com/sun/jna/platform/win32/COM/IEnumIDList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.sun.jna.platform.win32.COM; | ||
|
||
/* | ||
* Copyright (c) 2015 L W Ahonen, All Rights Reserved | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see other copyright notice examples in other files. Copy from there. |
||
* | ||
* | ||
*/ | ||
|
||
import com.sun.jna.Function; | ||
import com.sun.jna.Pointer; | ||
import com.sun.jna.platform.win32.Guid; | ||
import com.sun.jna.platform.win32.Guid.IID; | ||
import com.sun.jna.platform.win32.Guid.REFIID; | ||
import com.sun.jna.platform.win32.WinDef; | ||
import com.sun.jna.platform.win32.WinNT; | ||
import com.sun.jna.platform.win32.WinNT.HRESULT; | ||
import com.sun.jna.ptr.IntByReference; | ||
import com.sun.jna.ptr.PointerByReference; | ||
|
||
public interface IEnumIDList { | ||
|
||
/** | ||
* The Constant IID_IDispatch. | ||
*/ | ||
public final static IID IID_IEnumIDList = new IID( | ||
"{000214F2-0000-0000-C000-000000000046}"); | ||
|
||
HRESULT QueryInterface( | ||
Guid.GUID.ByReference riid, | ||
PointerByReference ppvObject); | ||
|
||
int AddRef(); | ||
|
||
int Release(); | ||
|
||
HRESULT Next( | ||
int celt, | ||
PointerByReference rgelt, | ||
IntByReference pceltFetched); | ||
|
||
HRESULT Skip( | ||
int celt); | ||
|
||
HRESULT Reset(); | ||
|
||
HRESULT Clone( | ||
PointerByReference ppenum); | ||
|
||
|
||
public static class Converter { | ||
public static IEnumIDList PointerToIEnumIDList(final PointerByReference ptr) { | ||
final Pointer interfacePointer = ptr.getValue(); | ||
final Pointer vTablePointer = interfacePointer.getPointer(0); | ||
final Pointer[] vTable = new Pointer[7]; | ||
vTablePointer.read(0, vTable, 0, 7); | ||
return new IEnumIDList() { | ||
|
||
@Override | ||
public WinNT.HRESULT QueryInterface(Guid.GUID.ByReference byValue, PointerByReference pointerByReference) { | ||
Function f = Function.getFunction(vTable[0], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT(f.invokeInt(new Object[]{interfacePointer, byValue, pointerByReference})); | ||
} | ||
|
||
@Override | ||
public int AddRef() { | ||
Function f = Function.getFunction(vTable[1], Function.ALT_CONVENTION); | ||
return f.invokeInt(new Object[]{interfacePointer}); | ||
} | ||
|
||
public int Release() { | ||
Function f = Function.getFunction(vTable[2], Function.ALT_CONVENTION); | ||
return f.invokeInt(new Object[]{interfacePointer}); | ||
} | ||
|
||
@Override | ||
public HRESULT Next(int celt, PointerByReference rgelt, IntByReference pceltFetched) { | ||
Function f = Function.getFunction(vTable[3], Function.ALT_CONVENTION); | ||
return new HRESULT(f.invokeInt(new Object[]{interfacePointer, celt, rgelt, pceltFetched})); | ||
} | ||
|
||
@Override | ||
public HRESULT Skip(int celt) { | ||
Function f = Function.getFunction(vTable[4], Function.ALT_CONVENTION); | ||
return new HRESULT(f.invokeInt(new Object[]{interfacePointer, celt})); | ||
} | ||
|
||
@Override | ||
public HRESULT Reset() { | ||
Function f = Function.getFunction(vTable[5], Function.ALT_CONVENTION); | ||
return new HRESULT(f.invokeInt(new Object[]{interfacePointer})); | ||
} | ||
|
||
@Override | ||
public HRESULT Clone(PointerByReference ppenum) { | ||
Function f = Function.getFunction(vTable[6], Function.ALT_CONVENTION); | ||
return new HRESULT(f.invokeInt(new Object[]{interfacePointer, ppenum})); | ||
} | ||
}; | ||
} | ||
} | ||
} |
182 changes: 182 additions & 0 deletions
182
contrib/platform/src/com/sun/jna/platform/win32/COM/IShellFolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package com.sun.jna.platform.win32.COM; | ||
|
||
/* | ||
* Copyright (c) 2015 L W Ahonen, All Rights Reserved | ||
* | ||
*/ | ||
|
||
import com.sun.jna.Function; | ||
import com.sun.jna.Pointer; | ||
import com.sun.jna.platform.win32.Guid; | ||
import com.sun.jna.platform.win32.Guid.IID; | ||
import com.sun.jna.platform.win32.Guid.REFIID; | ||
import com.sun.jna.platform.win32.WinDef; | ||
import com.sun.jna.platform.win32.WinNT; | ||
import com.sun.jna.platform.win32.WinNT.HRESULT; | ||
import com.sun.jna.ptr.IntByReference; | ||
import com.sun.jna.ptr.PointerByReference; | ||
|
||
public interface IShellFolder { | ||
|
||
/** The Constant IID_IDispatch. */ | ||
public final static IID IID_ISHELLFOLDER = new IID( | ||
"{000214E6-0000-0000-C000-000000000046}"); | ||
|
||
HRESULT QueryInterface( | ||
REFIID riid, | ||
PointerByReference ppvObject); | ||
|
||
int AddRef(); | ||
|
||
int Release(); | ||
|
||
HRESULT ParseDisplayName( | ||
WinDef.HWND hwnd, | ||
Pointer pbc, | ||
String pszDisplayName, | ||
IntByReference pchEaten, | ||
PointerByReference ppidl, | ||
IntByReference pdwAttributes); | ||
|
||
HRESULT EnumObjects( | ||
WinDef.HWND hwnd, | ||
int grfFlags, | ||
PointerByReference ppenumIDList); | ||
|
||
HRESULT BindToObject( | ||
Pointer pidl, | ||
Pointer pbc, | ||
REFIID riid, | ||
PointerByReference ppv); | ||
|
||
HRESULT BindToStorage( | ||
Pointer pidl, | ||
Pointer pbc, | ||
REFIID riid, | ||
PointerByReference ppv); | ||
|
||
HRESULT CompareIDs( | ||
WinDef.LPARAM lParam, | ||
Pointer pidl1, | ||
Pointer pidl2); | ||
|
||
HRESULT CreateViewObject( | ||
WinDef.HWND hwndOwner, | ||
REFIID riid, | ||
PointerByReference ppv); | ||
|
||
HRESULT GetAttributesOf( | ||
int cidl, | ||
Pointer apidl, | ||
IntByReference rgfInOut); | ||
|
||
HRESULT GetUIObjectOf( | ||
WinDef.HWND hwndOwner, | ||
int cidl, | ||
Pointer apidl, | ||
REFIID riid, | ||
IntByReference rgfReserved, | ||
PointerByReference ppv); | ||
|
||
HRESULT GetDisplayNameOf( | ||
Pointer pidl, | ||
int flags, | ||
PointerByReference pName); | ||
|
||
HRESULT SetNameOf( | ||
WinDef.HWND hwnd, | ||
Pointer pidl, | ||
String pszName, | ||
int uFlags, | ||
PointerByReference ppidlOut); | ||
|
||
|
||
|
||
public static class Converter | ||
{ | ||
public static IShellFolder PointerToIShellFolder(final PointerByReference ptr) | ||
{ | ||
final Pointer interfacePointer = ptr.getValue(); | ||
final Pointer vTablePointer = interfacePointer.getPointer(0); | ||
final Pointer[] vTable = new Pointer[13]; | ||
vTablePointer.read(0, vTable, 0, 13); | ||
return new IShellFolder() { | ||
|
||
@Override | ||
public WinNT.HRESULT QueryInterface(REFIID byValue, PointerByReference pointerByReference) { | ||
Function f = Function.getFunction(vTable[0], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT(f.invokeInt(new Object[]{interfacePointer, byValue, pointerByReference})); | ||
} | ||
|
||
@Override | ||
public int AddRef() { | ||
Function f = Function.getFunction(vTable[1], Function.ALT_CONVENTION); | ||
return f.invokeInt(new Object[]{interfacePointer}); | ||
} | ||
|
||
public int Release() { | ||
Function f = Function.getFunction(vTable[2], Function.ALT_CONVENTION); | ||
return f.invokeInt(new Object[]{interfacePointer}); | ||
} | ||
|
||
@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})); | ||
} | ||
|
||
@Override | ||
public WinNT.HRESULT EnumObjects(WinDef.HWND hwnd, int grfFlags, PointerByReference ppenumIDList) { | ||
Function f = Function.getFunction(vTable[4], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, hwnd, grfFlags, ppenumIDList})); | ||
} | ||
|
||
public WinNT.HRESULT BindToObject(Pointer pidl, Pointer pbc, REFIID riid, PointerByReference ppv) { | ||
Function f = Function.getFunction(vTable[5], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, pidl, pbc, riid, ppv})); | ||
} | ||
|
||
@Override | ||
public HRESULT BindToStorage(Pointer pidl, Pointer pbc, REFIID riid, PointerByReference ppv) { | ||
Function f = Function.getFunction(vTable[6], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, pidl, pbc, riid, ppv})); | ||
} | ||
|
||
@Override | ||
public HRESULT CompareIDs(WinDef.LPARAM lParam, Pointer pidl1, Pointer pidl2) { | ||
Function f = Function.getFunction(vTable[7], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, lParam, pidl1, pidl2})); | ||
} | ||
|
||
@Override | ||
public HRESULT CreateViewObject(WinDef.HWND hwndOwner, REFIID riid, PointerByReference ppv) { | ||
Function f = Function.getFunction(vTable[8], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, hwndOwner, riid, ppv})); | ||
} | ||
|
||
@Override | ||
public HRESULT GetAttributesOf(int cidl, Pointer apidl, IntByReference rgfInOut) { | ||
Function f = Function.getFunction(vTable[9], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, cidl, apidl, rgfInOut})); | ||
} | ||
|
||
@Override | ||
public HRESULT GetUIObjectOf(WinDef.HWND hwndOwner, int cidl, Pointer apidl, REFIID riid, IntByReference rgfReserved, PointerByReference ppv) { | ||
Function f = Function.getFunction(vTable[10], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, hwndOwner, cidl, apidl, riid, rgfReserved, ppv})); | ||
} | ||
|
||
public WinNT.HRESULT GetDisplayNameOf(Pointer pidl, int flags, PointerByReference pName){ | ||
Function f = Function.getFunction(vTable[11], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, pidl, flags, pName})); | ||
} | ||
|
||
@Override | ||
public HRESULT SetNameOf(WinDef.HWND hwnd, Pointer pidl, String pszName, int uFlags, PointerByReference ppidlOut) { | ||
Function f = Function.getFunction(vTable[12], Function.ALT_CONVENTION); | ||
return new WinNT.HRESULT( f.invokeInt(new Object[]{interfacePointer, hwnd, pidl, pszName, uFlags, ppidlOut})); | ||
} | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be a pest, can you please make this look like the other lines "Added com.sun....", this is otherwise particularly confusing to non Windows people.