schullq
2017-04-28 09:56:50 UTC
Hello,
I started using SWIG to wrap a C++ library, in order to use it in C#.
I am playing arround with typemaps, in order to get rid of all the
SWIGTYPE_* class (which I understand are created because did'nt know how to
wrap a certain type.
Anyway, I am having trouble with a simple typemap. I have multiple methods
that return unsigned char * in C++, which need to be consider as unsigned
char arrays. I found in "array_csharp.i" that there are multiple ways to
handle this situation. I tried them all but I never get the correct result
like the example in the doc.
Here is my c++ method:
/inline unsigned char* getData() { return d_key; };/
Here are all the implementations I tried to set the correct typemap using
%apply:
1. /%apply unsigned char OUTPUT[] { unsigned char* getData() }/
2. /%apply unsigned char OUTPUT[] { unsigned char* }/
3. /%apply unsigned char FIXED[] { unsigned char* getData() }/
/%csmethodmodifiers getData "public unsafe";/
But nothing, I always got this result:
- For tries 1 and 2:
/ public virtual byte[] getData() {
global::System.IntPtr cPtr =
libdataPINVOKE.Key_getData__SWIG_0(swigCPtr);
SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ?
null : new SWIGTYPE_p_unsigned_char(cPtr, false);
return ret;
}/
- For try 3:
/ public unsafe byte[] getData() {
global::System.IntPtr cPtr =
libdataPINVOKE.Key_getData__SWIG_0(swigCPtr);
SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ?
null : new SWIGTYPE_p_unsigned_char(cPtr, false);
return ret;
}/
I can't understand why the mapping only works for the declaration return
value.
If someone have a hint, I would be very pleased.
schullq.
--
View this message in context: http://swig.10945.n7.nabble.com/SWIG-C-Default-typemap-to-handle-unsigned-char-as-array-going-strange-tp15148.html
Sent from the swig-user mailing list archive at Nabble.com.
I started using SWIG to wrap a C++ library, in order to use it in C#.
I am playing arround with typemaps, in order to get rid of all the
SWIGTYPE_* class (which I understand are created because did'nt know how to
wrap a certain type.
Anyway, I am having trouble with a simple typemap. I have multiple methods
that return unsigned char * in C++, which need to be consider as unsigned
char arrays. I found in "array_csharp.i" that there are multiple ways to
handle this situation. I tried them all but I never get the correct result
like the example in the doc.
Here is my c++ method:
/inline unsigned char* getData() { return d_key; };/
Here are all the implementations I tried to set the correct typemap using
%apply:
1. /%apply unsigned char OUTPUT[] { unsigned char* getData() }/
2. /%apply unsigned char OUTPUT[] { unsigned char* }/
3. /%apply unsigned char FIXED[] { unsigned char* getData() }/
/%csmethodmodifiers getData "public unsafe";/
But nothing, I always got this result:
- For tries 1 and 2:
/ public virtual byte[] getData() {
global::System.IntPtr cPtr =
libdataPINVOKE.Key_getData__SWIG_0(swigCPtr);
SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ?
null : new SWIGTYPE_p_unsigned_char(cPtr, false);
return ret;
}/
- For try 3:
/ public unsafe byte[] getData() {
global::System.IntPtr cPtr =
libdataPINVOKE.Key_getData__SWIG_0(swigCPtr);
SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ?
null : new SWIGTYPE_p_unsigned_char(cPtr, false);
return ret;
}/
I can't understand why the mapping only works for the declaration return
value.
If someone have a hint, I would be very pleased.
schullq.
--
View this message in context: http://swig.10945.n7.nabble.com/SWIG-C-Default-typemap-to-handle-unsigned-char-as-array-going-strange-tp15148.html
Sent from the swig-user mailing list archive at Nabble.com.