Results 1 to 2 of 2
  1. #1
    Sanjeev is offline Member
    Join Date
    Jul 2011
    Rep Power

    Default 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(
    at com.sun.jna.Function.invoke(
    at com.sun.jna.Library$Handler.invoke( 6)
    at $Proxy0.mcd_qry_reg_map_f(Unknown Source)

    Please suggest me the probable reason and solution for error 'Invalid memory access'.


  2. #2
    Sanjeev is offline Member
    Join Date
    Jul 2011
    Rep Power


    I got the solution correct mapping of C method
    mcd_open_core_f(const mcd_core_con_info_st *core_con_info, mcd_core_st **core);
    in java
    mcd_open_core_f(MCDCoreConnectionInfo core_con_info, PointerByReference cores);

Similar Threads

  1. Replies: 0
    Last Post: 05-27-2011, 08:46 AM
  2. Replies: 3
    Last Post: 09-27-2010, 07:07 AM
  3. Replies: 1
    Last Post: 03-24-2009, 01:52 PM
  4. Invalid Thread Access?
    By xcallmejudasx in forum Advanced Java
    Replies: 1
    Last Post: 10-30-2008, 11:08 PM
  5. How to over come java.lang.out of memory error
    By Chaitra_gm in forum New To Java
    Replies: 5
    Last Post: 09-28-2008, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts