JNA Invalid memory access Unknown Interface

0

I tried everything but it is always returning an Invalid memory access expection This is the c function:

HRESULT GetImage(
  SIZE    size,
  SIIGBF  flags,
  HBITMAP *phbm
);

And this is may java implementation:

WinUser.SIZE size = new WinUser.SIZE(64,64);
WinDef.HBITMAP bitmap = new WinDef.HBITMAP();

factory.GetImage(size,0,bitmap);

And this is the IShellItemImageFactory class:

package main;

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.COM.Unknown;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;

/**
 * Created by Marcel on Aug,2018
 */
public class IShellItemImageFactory extends Unknown {
    public IShellItemImageFactory(Pointer pvInstance) {
        super(pvInstance);
    }

    WinNT.HRESULT GetImage(WinUser.SIZE size, int flags, WinDef.HBITMAP phbm) {
        return (WinNT.HRESULT) _invokeNativeObject(3,new Object[]{getPointer(),size,flags,phbm},WinNT.HRESULT.class);
    }
}

But in the end it always returns this expection:

Exception in thread "main" java.lang.Error: Invalid memory access
    at com.sun.jna.Native.invokeInt(Native Method)
    at com.sun.jna.Function.invoke(Function.java:419)
    at com.sun.jna.Function.invoke(Function.java:354)
    at com.sun.jna.Function.invoke(Function.java:308)
    at com.sun.jna.Function.invoke(Function.java:299)
    at com.sun.jna.platform.win32.COM.COMInvoker._invokeNativeObject(COMInvoker.java:47)
    at main.IShellItemImageFactory.GetImage(IShellItemImageFactory.java:20)
    at main.Main.main(Main.java:35)

Shell32Extra:

public interface Shell32Extra extends com.sun.jna.platform.win32.Shell32 {

Shell32Extra INSTANCE = (Shell32Extra)Native.loadLibrary("shell32", Shell32Extra.class, W32APIOptions.DEFAULT_OPTIONS);

WinNT.HRESULT SHCreateItemFromParsingName(WString pszPath, Pointer p, Guid.REFIID riid, PointerByReference ppv);

String IID_IShellItem2 = "7E9FB0D3-919F-4307-AB2E-9B1860310C93";

public static interface SIIGBF {
    public static final long SIIGBF_RESIZETOFIT = (long)0x00;
    public static final long SIIGBF_BIGGERSIZEOK = 0x00000001;
    public static final long SIIGBF_MEMORYONLY = 0x00000002;
    public static final long SIIGBF_ICONONLY  = 0x00000004;
    public static final long SIIGBF_THUMBNAILONLY  = 0x00000008;
    public static final long SIIGBF_INCACHEONLY  = 0x00000010;
};

public static interface _SIGDN {
    public static final int SIGDN_NORMALDISPLAY = 0;
    public static final int SIGDN_PARENTRELATIVEPARSING = 1;
    public static final int SIGDN_DESKTOPABSOLUTEPARSING = 2;
    public static final int SIGDN_PARENTRELATIVEEDITING = 3;
    public static final int SIGDN_DESKTOPABSOLUTEEDITING = 4;
    public static final int SIGDN_FILESYSPATH = 5;
    public static final int SIGDN_URL = 6;
    public static final int SIGDN_PARENTRELATIVEFORADDRESSBAR = 7;
    public static final int SIGDN_PARENTRELATIVE = 8;
    public static final int SIGDN_PARENTRELATIVEFORUI = 9;
};

}

Ole32Extra:

public interface Ole32Extra extends com.sun.jna.platform.win32.Ole32 {
Ole32Extra INSTANCE = Native.loadLibrary("Ole32", Ole32Extra.class, W32APIOptions.DEFAULT_OPTIONS);

int RPC_C_AUTHN_LEVEL_DEFAULT = 0;
int RPC_C_AUTHN_WINNT = 10;
int RPC_C_IMP_LEVEL_IMPERSONATE = 3;
int RPC_C_AUTHZ_NONE = 0;
int RPC_C_AUTHN_LEVEL_CALL = 3;

int EOAC_NONE = 0;


HRESULT CoInitializeSecurity(SECURITY_DESCRIPTOR pSecDesc, int cAuthSvc, Pointer asAuthSvc, Pointer pReserved1,
                             int dwAuthnLevel, int dwImpLevel, Pointer pAuthList, int dwCapabilities, Pointer pReserved3);

HRESULT CoSetProxyBlanket(Pointer pProxy, //
                          int dwAuthnSvc, //
                          int dwAuthzSvc, //
                          LPOLESTR pServerPrincName, //
                          int dwAuthnLevel, //
                          int dwImpLevel, //
                          Pointer pAuthInfo, // RPC_AUTH_IDENTITY_HANDLE
                          int dwCapabilities//
);

void CoUninitialize();

}

I am creating the IShellItemImageFactory like this:

WinNT.HRESULT h = Shell32Extra.INSTANCE.SHCreateItemFromParsingName(new 
WString("C:\\Users\\Marcel\\Desktop\\Modern File Explorer 
0.2a.jar"),null,rid,ppv);

PointerByReference b = new PointerByReference();
IShellItemImageFactory factory = new IShellItemImageFactory(ppv.getValue());

PointerByReference b = new PointerByReference();
IShellItemImageFactory factory = new IShellItemImageFactory(ppv.getValue());
WinUser.SIZE size = new WinUser.SIZE(64,64);
WinDef.HBITMAP bitmap = new WinDef.HBITMAP();
factory.GetImage(size,0,bitmap);

But it always returns an Invalid memory access expection

java
c
jna
asked on Stack Overflow Sep 15, 2018 by Stats • edited Oct 21, 2018 by Stats

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0