Sziasztok,
Elnézést előre is mert hosszú lesz.
Adott egy C++ ban irt dll, aminek a forrásához nincs hozzáférésem. Ennek bizonyos funckóit szeretném java alol meghivni
A egyik c++ funkcio deklarációja igy néz ki
struct nc_appinfo {
char appcd[4];
char appname[256];
char ver[32];
UINT kind;
UINT secmod
};
struct nc_userinfo {
char groupno[12];
char groupname[256];
char userno[12];
char username[21];
char password[15];
UINT dataaccess;
};
int nc_app_start( int hWnd, int* logonid, nc_appinfo* appinfo, nc_userinfo* usrinfo,char* accessfile, int* errorinfo) ;
Ezt igy forditottam Java-ra:
public class MyLibrary implements Library {
public static final String JNA_LIBRARY_NAME = "usr.dll";
public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(MyLibrary.JNA_LIBRARY_NAME);
static {
Native.register(MyLibrary.JNA_LIBRARY_NAME);
}
public static class nc_appinfo extends Structure {
public byte[] appcd = new byte[(4)];
public byte[] appname = new byte[(256)];
public byte[] ver = new byte[(32)];
public int kind;
public int secmode;
};
public static class nc_userinfo extends Structure {
public byte[] groupno = new byte[(12)];
public byte[] groupname = new byte[(256)];
public byte[] userno = new byte[(12)];
public byte[] username = new byte[(21)];
public byte[] password = new byte[(15)];
public int dataaccess;
};
public static native int nc_app_start(IntBuffer hWnd, IntBuffer logonid, Pointer appinfo, Pointer usrinfo, String accessfile, IntBuffer errorinfo);
és igy hivom meg:
MyLibrary.nc_appinfo app = new nc_appinfo();
MyLibrary.nc_userinfo user = new nc_userinfo();
IntBuffer logonid = null;
logonid.allocate(5);
IntBuffer errorinfo = null;
errorinfo.allocate(5);
final IntBuffer hwnd = null;
hwnd.allocate(5);
String accessfile = null;
int result = 0;
try {
result = MyLibrary.nc_app_start(hwnd, logonid, app.getPointer(), user.getPointer(), accessfile, errorinfo);
System.out.println(result);
} catch (Exception e) {
System.out.println(e.getMessage());
}
futtatáskor ezt a szép üzenetet kapom:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x04ed8679, pid=5588, tid=752
#
# JRE version: 6.0_30-b12
# Java VM: Java HotSpot(TM) Client VM (20.5-b03 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [usr.dll+0x8679]
#
ugyanez a dll és funkció c#/.NET alól tökéletesen megy.
Ilyesmit még nem igazán csináltam Java alól, szóval ne kiméljetek ötletekkel...