Jvm JNA调用适用于32位JRE,但不适用于64位JRE

Jvm JNA调用适用于32位JRE,但不适用于64位JRE,jvm,java,jna,Jvm,Java,Jna,我试图从我创建的JNA接口调用system32的CreateProcessW。问题是,当我从32位JRE运行软件时,它工作正常,但当我转到64位JRE时,它会使JVM崩溃 Kernel32 kernel = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class, new HashMap<String, Object>() { private static final long seri

我试图从我创建的JNA接口调用system32的CreateProcessW。问题是,当我从32位JRE运行软件时,它工作正常,但当我转到64位JRE时,它会使JVM崩溃

Kernel32 kernel = (Kernel32) Native.loadLibrary("kernel32",
        Kernel32.class, new HashMap<String, Object>() {
            private static final long serialVersionUID = 1L;

            {
                put(Library.OPTION_FUNCTION_MAPPER,
                        W32APIFunctionMapper.UNICODE);
                put(Library.OPTION_TYPE_MAPPER,
                        W32APITypeMapper.UNICODE);
            }
        });

ProcessInformation processInformation = new ProcessInformation();
byte[] startupInfo = new byte[67];

int num2 = BitConverter.toInt32(bytes, 60);
int num = BitConverter.toInt16(bytes, num2 + 6);
IntByReference ptr4 = new IntByReference(BitConverter.toInt32(bytes, num2 + 0x54));
kernel.CreateProcessW(surrogateProcess, null, 0, 0, false, 4, 0,
            null, startupInfo, processInformation);
My ProcessInformation JNA结构:

public final class ProcessInformation extends Structure implements ByReference {

    public IntByReference hProcess;
    public IntByReference hThread;
    public int dwProcessId;
    public int dwThreadId;

    @Override
    protected List<String> getFieldOrder() {
        return Arrays
                .asList("hProcess", "hThread", "dwProcessId", "dwThreadId");
    }

}
你的地图是假的。您是从哪里想到可以使用Java
int
来表示指针值的?哦,没关系,win32 API一定教会了你这一点

您必须使用
指针
指针类型
或等效物来表示指针,或者如果您确实坚持使用整数值,至少在64位平台上使用
long
(64位)

顺便说一句,JNA包括一个
platform.jar
,其中包括内核32映射,包括
CreateProcess

public final class ProcessInformation extends Structure implements ByReference {

    public IntByReference hProcess;
    public IntByReference hThread;
    public int dwProcessId;
    public int dwThreadId;

    @Override
    protected List<String> getFieldOrder() {
        return Arrays
                .asList("hProcess", "hThread", "dwProcessId", "dwThreadId");
    }

}
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077a4e711, pid=1888, tid=8968
#
# JRE version: 6.0_43-b01
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.14-b01 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [ntdll.dll+0x4e711]
#
# An error report file with more information is saved as:
# C:\Users\Thomas\workspace\trident\hs_err_pid1888.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#