Skip to content
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
merged 12 commits into from
Dec 4, 2015
1 change: 1 addition & 0 deletions CHANGES.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Features
* [#512](https://github.com/java-native-access/jna/pull/512): Make loading debug flags mutable [@lwahonen](https://github.com/lwahonen).
* [#514](https://github.com/java-native-access/jna/pull/514): Added `host_processor_info` to `com.sun.jna.platform.mac.SystemB` - [@dbwiddis](https://github.com/dbwiddis).
* [#519](https://github.com/java-native-access/jna/pull/519): Added JNA functional overview - [@twall](https://github.com/twall).
* [#524](https://github.com/java-native-access/jna/pull/524): IShellFolder interface plus necessary interfaces, and a sample for enumerating objects in My Computer - [@lwahonen](https://github.com/lwahonen).
Copy link
Member

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.


Bug Fixes
---------
Expand Down
101 changes: 101 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/COM/IEnumIDList.java
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
Copy link
Member

Choose a reason for hiding this comment

The 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 contrib/platform/src/com/sun/jna/platform/win32/COM/IShellFolder.java
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}));
}
};
}
}
}
Loading