使用JNA获取ShellIconOverlayIdentifier的图标文件和图像编号

时间:2019-04-30 13:56:27

标签: windows java icons overlay

我发现this example用于使用某些C / C ++代码查询图标文件和图像编号以获取外壳图标叠加层标识符。 不幸的是,我不是C ++开发人员,所以我尝试使用JNA用Java编写代码。

因此,我为IShellIconOverlayIdentifier创建了接口:

public interface IShellIconOverlayIdentifier extends IUnknown {

    public final static IID IID_ISHELLICONOVERLAYIDENTIFIER = new IID("{0C6C4200-C589-11D0-999A-00C04FD655E1}");

    HRESULT GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, IntByReference pIndex, DWORDByReference pdwFlags);

    HRESULT GetPriority(IntByReference pPriority);

    HRESULT IsMemberOf(WString pwszPath, DWORD dwAttrib);
}

以及相应的实现类ShellIconOverlayIdentifier:

public class ShellIconOverlayIdentifier extends Unknown implements IShellIconOverlayIdentifier {

    public ShellIconOverlayIdentifier() {
    }

    public ShellIconOverlayIdentifier(Pointer pvInstance) {
        super(pvInstance);
    }

    @Override
    public HRESULT GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, IntByReference pIndex, DWORDByReference pdwFlags) {
        return (HRESULT) this._invokeNativeObject(3, new Object[] { this.getPointer(), pwszIconFile, cchMax, pIndex, pdwFlags }, HRESULT.class);
    }

    @Override
    public HRESULT GetPriority(IntByReference pPriority) {
        return (HRESULT) this._invokeNativeObject(4, new Object[] { this.getPointer(), pPriority }, HRESULT.class);
    }

    @Override
    public HRESULT IsMemberOf(WString pwszPath, DWORD dwAttrib) {
        return (HRESULT) this._invokeNativeObject(5, new Object[] { this.getPointer(), pwszPath, dwAttrib }, HRESULT.class);
    }
}

但是如果我现在尝试使用这些类

HRESULT hr;

hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_MULTITHREADED);
COMUtils.checkRC(hr);

GUID clsid = Ole32Util.getGUIDFromString("{C5994560-53D9-4125-87C9-F193FC689CB2}"); // DropboxExt01
PointerByReference ppv = new PointerByReference();
hr = Ole32.INSTANCE.CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_ISHELLICONOVERLAYIDENTIFIER, ppv);
COMUtils.checkRC(hr);

Unknown u = new Unknown(ppv.getValue());
PointerByReference pbr = new PointerByReference();
hr = u.QueryInterface(new REFIID(IID_ISHELLICONOVERLAYIDENTIFIER), pbr);
COMUtils.checkRC(hr);

ShellIconOverlayIdentifier pISIOI = new ShellIconOverlayIdentifier(ppv.getValue());

LPWSTR pwszIconFile = new LPWSTR();
DWORDByReference pdwFlags = new DWORDByReference();
IntByReference pIndex = new IntByReference();

hr = pISIOI.GetOverlayInfo(pwszIconFile, 128, pIndex, pdwFlags);
COMUtils.checkRC(hr);

System.out.println("Icon Path:\n    " + pwszIconFile.getValue() + " " + pIndex.getValue());
pISIOI.Release();

Ole32.INSTANCE.CoUninitialize();

我在执行过程中遇到以下异常:

Exception in thread "main" com.sun.jna.platform.win32.COM.COMException: An den Stub wurde ein Nullzeiger übergeben.(HRESULT: 800706f4)
    at com.sun.jna.platform.win32.COM.COMUtils.checkRC(COMUtils.java:117)
    at overlay.Test.main(Test.java:45)

有没有人可以帮助我使用该代码?

0 个答案:

没有答案