I solved it!
    Finally I had to implement something that I think will make my life very easy from now on!
    I have converted the C API to a C++ API class based. I have created a class that puts together all the methods for my hidden types ( by hidden I mean the ones defined by typedef void * MYTYPE ).
    This has allowed me to obtain a Java class for each of the types and I can manipulate all the C pointer management in my wrapper, in fact there is very simple.
    So for my type data, that was:

typedef void * data;

int  data_create (int data_type,data *d );

// the data type is manipulated in several diferent ways
int  data_type (data d );
I have created a class
class Cdata{
data ptr;
Cdata(int data_type){
int type(){
return data_type(ptr);
/* and so on .....*/
this way I think the solution is quite straightforward and to be honest I think it could even be automatically generated.
Mark, thanks for your advise, it was very useful when I was in the middle of my investigations to have some of your comments.
Just a point here, the wrapper function you suggested: void** voidp_address(void* ptr){return &ptr;}
doesn´t work as it returns the pointer to the local variable, so I guess it should be defined like a macro (or maybe inline code?), is that correct?
I hope sharing my experience helps others to make progress.
Kind regards

On 5/23/06, mark gossage <Mark@gossage.cjb.net> wrote:
Hello Jose,

I am not a SWIG-JAVA person, but I can see some of your problem, so I will advise on that side:

>     SWIGTYPE_p_p_void pd;
>     SWIGTYPE_p_void d;
>     agt.opcdata_create(opcapiagt.OPCDATA_MSG, pd);
>     d=3Dagt.voidpp_value(pd);

This is wrong, because it becomes effectively the following C code:
void** pd;
void* d;
agt.opcdata_create(opcapiagt.OPCDATA_MSG, pd); // this is not good
d=*pd; // this will certainly coredump

You need to write you code more like:
void* d;
void** pd=&d
agt.opcdata_create (opcapiagt.OPCDATA_MSG, pd); // this is not good
// then use d

This is your problem, now how to solve it.

You could write and wrapper a function
void** voidp_address(void* ptr){return &ptr;}
This would allow you to get the task done.

Another slightly neater way might be modify the wrappers.
Instead of
void opcdata_create(int ID,void** pd);

use SWIG's %extend (I believe it works in java)
%extend SomeClass %{
void* opcdata_create2(int ID)
   void* ptr;
   return ptr;

Then you could just have

SWIGTYPE_p_void d=agt.opcdata_create2(opcapiagt.OPCDATA_MSG );

Which looks much neater.

This third option is to use an OUTPUT typemap, which would give you the same kind of results as the second option, but would probably need a little less coding. The thing is that the typemaps are more language specific, so I am not so sure on this.

Hope this helps,
Mark Gossage

> Hello,
>    I have made some progress, but still facing some difficulties.
>    I have used the pointer macro: %pointer_functions(void *, voidpp);
>    that creates the four methods to manipulate the handle that the type dat=
> a
> is mapped to.
>    Then I used the code this way:
>     SWIGTYPE_p_p_void pd;
>     SWIGTYPE_p_void d;
>     agt.opcdata_create(opcapiagt.OPCDATA_MSG, pd);
>     d=3Dagt.voidpp_value(pd);
>      where I receive the error that pd has not been initialized, what in
> fact is not needed.
>     How do I specify this?
>     I have found on the documentation that there are different typemaps for
> java and for a generic. When should the java ones be used instead of the
> generics?
>     Another topic, I have tried to generate a java class using SWIG that
> directly works with the type data ( typedef void * data ), but it has not
> been possible to obtain a class like SWIGTYPE_data or anything similar as
> the typedef looks to get preference. The alternative would be to generate i=
> t
> myself on top of the code generated by SWIG but this will create a coupling
> I would like to avoid if possible.
>     Thanks in advance for your help
>          Jose

Jose A. Magaña

Vale más hacer y arrepentirse, que no hacer y arrepentirse