|
Re: Java char *INOUT doesn't OUT: msg#00152programming.swig
William, Thanks for the input. For clarification, the char* are basically strings (not single chars) that are passed back and forth with this DLL. Does the signed char * properly handle null terminating the Strings? Thanks, Gary At 04:06 PM 9/22/2004, William S Fulton wrote: >Gary Nissen wrote: > >>Hi, >>I'm using SWIG-1.3.22 on Windows with Java JDK 1.4.2. >>I'm trying to wrap a C DLL. All parameters are passed as pointers (int *, >>double *, and char *). Most parameters are *INPUT, but some are *INOUT. The >>int *INOUT and double *INOUT work as expected by turning the parameter into a >>single dimensional array. But a char *INOUT turns the parameter into a >>String, basically making it a char *INPUT. >>I expected the char *INOUT to allow me to pass Strings back and forth via a >>1-dimensional array just like int *INOUT. Am I off track? Is there a better >>method to do this? >>Through my struggles I also tried the *SBUF and *BYTE methods. Unfortunately >>neither worked for me. >>The *SBUF caused Access Violations because the char array was a different >>length than the string contained in the StringBuffer. It was using the >>capacity of a StringBuffer instead of the length of the String contained in >>it. I tried changing the typemap to use length. Then I received Access >>Violations when the resulting string was being appended back to the >>StringBuffer. I wasn't able to figure out why that was failing. >>The *BYTE caused garbage to be pasted back into my String. I was using the >>BYTE method this way: >>String s = "0123456789"; >>byte[] b = s.toByteArray(); >>int r = DLLWrapper.getResult(b); >>s = new String(b); >>System.out.println(s); >>This resulted in garbage printouts. >>Any advice on the best/easiest way to do this? > >SWIG wraps char* as a string, that is well documented. To change the behaviour >of char* to a pointer to an in/out single char character, apply the 'signed >char *' typemaps. > >%include "typemaps.i" >%apply signed char *INOUT {char *pnum}; >%typemap(freearg) char *pnum ""; > >void foo(char *pnum); > >Unfortunately the default char* typemaps require a freearg typemap and this is >still picked up, thus the extra typemap above to clear the freearg typemap. >I'll change this so it won't be necessary in the future. > >William >_______________________________________________ >Swig maillist - Swig@xxxxxxxxxxxxxxx >http://mailman.cs.uchicago.edu/mailman/listinfo/swig _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Python and Submodules: 00152, Robin Dunn |
|---|---|
| Next by Date: | Problems with %rename (const): 00152, Emanuel Greisen |
| Previous by Thread: | Re: Java char *INOUT doesn't OUTi: 00152, William S Fulton |
| Next by Thread: | RE: Java char *INOUT doesn't OUT: 00152, William . Fulton |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |