Results 1 to 2 of 2
- 07-08-2011, 04:37 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
java.lang.Error: Invalid memory access while using JNA call
I am using jna.jar to call native API(dll) that is written in c/c++.
One of the call is throwing 'Invalid memory access'.
A structre written in C is
typedef struct {
void *instance;
const mcd_core_con_info_st *core_con_info;
} mcd_core_st;
The equivalent structre in java I have written is.
public class MCDCore extends Structure {
public static class ByValue extends MCDCore implements Structure.ByValue {}
public static class ByReference extends MCDCore implements Structure.ByReference {}
public Pointer instance = new Pointer(-1);
public MCDCoreConnectionInfo.ByReference coreConInfo = null;
}
Where MCDCoreConnectionInfo is another structure and I guess this structure is correct because I am successfully able to make calls using this structure.
C methods definition
mcd_open_core_f(const mcd_core_con_info_st *core_con_info, mcd_core_st **core);
equivalent java method.
public mcd_open_core_f(MCDCoreConnectionInfo core_con_info, Pointer core);
Another C method
mcd_qry_reg_map_f(const mcd_core_st *core, int reg_group_id, int start_index, int *num_regs, mcd_register_info_st *reg_info);
equvalent Java method
public void mcd_qry_reg_map_f(MCDCore core, int regGroupId, int i,IntByReference numRegs, MCDRegisterInfo regInfo);
Now working C code.
mcd_core_st *core;
mcd->mcd_open_core_f(&core_con_info_core, &core);
mcd_register_info_st core_ip_reg;
int reg_group_id = 0;
int num_regs = 0;
mcd->mcd_qry_reg_map_f(core, reg_group_id, 0, &num_regs, 0);
equvalent code written in java
Now when I make call in C++.
mcd_core_st *core;
mcd->mcd_open_core_f(&core_con_info_core, &core);
Equvalent code in java
MCDCore core = new MCDCore();
mcdAPI.mcd_open_core_f(coreInfo, core.getPointer());
// this is successfull call.
MCDRegisterInfo regInfo = new MCDRegisterInfo();
IntByReference num_regs = new IntByReference(0);
int reg_group_id = 0;
mcdAPI.mcd_qry_reg_map_f(core, reg_group_id, reg_group_id,num_regs, null);
// this line gives following error.
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Function.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:344)
at com.sun.jna.Function.invoke(Function.java:276)
at com.sun.jna.Library$Handler.invoke(Library.java:21 6)
at $Proxy0.mcd_qry_reg_map_f(Unknown Source)
at com.kpit.mcd.jna.Main.main(Main.java:104)
Please suggest me the probable reason and solution for error 'Invalid memory access'.
.gif)
-Sanjeev
- 07-12-2011, 01:02 PM #2
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Servlet, Glassfish JMS java.lang.IllegalArgumentException: MQ:Queue:Invalid Queue Nam
By akasozi in forum Java ServletReplies: 0Last Post: 05-27-2011, 08:46 AM -
java.lang.IndexOutOfBoundsException: Invalid location 1, size is 2
By biswajithit in forum AndroidReplies: 3Last Post: 09-27-2010, 07:07 AM -
getting following error org.eclipse.swt.SWTException: Invalid thread access
By Madhavee Latha in forum SWT / JFaceReplies: 1Last Post: 03-24-2009, 12:52 PM -
Invalid Thread Access?
By xcallmejudasx in forum Advanced JavaReplies: 1Last Post: 10-30-2008, 10:08 PM -
How to over come java.lang.out of memory error
By Chaitra_gm in forum New To JavaReplies: 5Last Post: 09-28-2008, 10:33 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks