Hi,

I posted what was going wrong for me with Swig but got no reply.  My post was rather long and what I really want to know is given the following code in C :

     typdef struct
    {
        int * i1;
        char* c1;
        int len;
    } MY_STRUCT;
   
    bool myfunc (MY_STRUCT* pms)
    {
        strncpy (pms->c1, "Hello from the world of Swig", pms->len);
        *pms->i1 = strlen(pms->c1);
    }

What do I need to put in a .i file and what java code in a .java file in order to be able to have read and write access to java data in my C code ? (I.e. read and write through pointers ?).

My .i file is effectively the same as what follows below and if anyone can tell me why I get flakey problems when I write to the i1 and c1 elements of MY_STRUCT thenm I would be grateful.  I am using Swig Version 3.0.2 on Mac OS X Mavericks.

Many thanks,

Mike


/* File : MY_STRUCT.i */
%module MY_STRUCT

// Enable the JNI class to load the required native library.
%pragma(java) jniclasscode=%{
 static {
 try {
 java.lang.System.loadLibrary("MY_STRUCT");
 } catch (UnsatisfiedLinkError e) {
 java.lang.System.err.println("native code library failed to load.\n" + e);
 java.lang.System.exit(1);
 }
 }
%}

%include <typemaps.i>
%apply byte * INOUT {char*};
%apply int * INOUT {int*};

typdef struct
{
    int * i1;
    char* c1;
    int len;
} MY_STRUCT;

%include cpointer.i

bool myfunc (MY_STRUCT* pms)
{
    strncpy (pms->c1, "Hello from the world of Swig", pms->len);
    *pms->i1 = strlen(pms->c1);
}

%pointer_functions(int, intp);