How to pass a value to a function when the value is SWIGTYPE

亡梦爱人 提交于 2019-12-25 00:36:09

问题


I have a wrapped function in java like this:

dosomething(SWIGTYPE_sometypeSTRUCT STRUCTtype);

Originally in the C code, the declaration looks so:

dosomething(sometypeSTRUCT* structtype);

How can I pass the SWIGTYPE to the java function. if I do: SWIGTYPE_sometypeSTRUCT something = new SWIGTYPE_sometypeSTRUCT ();

it won't work.. It will work only if I set somthing = null.


回答1:


The problem is that SWIG hasn't seen a definition of sometypeSTRUCT - as far as it knows the pointer your dosomething function takes is an opaque type.

When SWIG doesn't know details it can't wrap it meaningfully and the only safe thing to do is let you do what you would be able to do in C with such a type.

To fix this you probably want to use %include to bring in the definition of the struct, or possibly provide a definition within the SWIG interface file.



来源:https://stackoverflow.com/questions/12856490/how-to-pass-a-value-to-a-function-when-the-value-is-swigtype

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!