|
From: Clinton C. <cli...@ya...> - 2005-11-15 05:37:54
|
Hi all, I am using SWIG to wrap a C library for use in some C# programs. I have run into the following problem: how do I wrap calls into the C library that allocate memory for structs? I have studied the example that is provided in the SWIG documentation for the analogous problem in Java (section 19.9.10 in the 1.3 documentation). The problem I have is, how can I pass back the C pointer to the structure that has been allocated by the C routine? In JNI, there are facilities to allow the JNI code to directly access and modify the members of a particular instance of a class. Unfortunately, these facilities don't exist for the C# case. Am I missing something really simple? I have contemplated using the [StructLayout...] attribute using the csattribute typemap, and also passing by reference a IntPtr object to hold the the C pointer and then replacing the swigCPtr object when the P/Invoke call returns. But there has to be a more elegant solution, right? Thanks in advance for any aid you can provide. Clinton Chau __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com |