Le 22/11/2011 18:56, Randall Morgan a écrit : > I do the C structures defined. But the functions return pointers to the > structures created by Tidy. So I have to Read the data into my local copy > using the pointer returned. Which I feel is very inefficient. I have just > started to play around with defining offset values for each location in the > structure returned by tidy and simply accessing tidy's structures directly. > I feel this is more efficient that making local copies of the structures. > > I am new to Gambas but not programming in general. So any pointer on how > best to work with external libraries would be helpful. Once I have a well > defined interface to the external library I want to package it as a > component. There other external libraries I'd like to package as components > as well. So this is just my first attempted. I've had some minor successes > so far. But I want to make the library wrapper as useful as possible by > including at least a reasonable subset of Tidy's capabilities. > > I would love to see some Gambas 3 samples code for reading and writing > c-structures using pointers.... > >
Hi, In revision #4257, I have added support for extern functions that return a pointer to a C structure. So... To send a structure pointer to an extern function, do that: --8<----------------------------------------------------------------- Public Struct StructTm tm_sec As Integer tm_min As Integer tm_hour As Integer tm_mday As Integer tm_mon As Integer tm_year As Integer tm_wday As Integer tm_yday As Integer tm_isdst As Integer End Struct Private Extern asctime(tm As StructTm) As String In "libc:6" --8<----------------------------------------------------------------- And to get a structure pointer from an extern function, do that: --8<----------------------------------------------------------------- Public Struct StructTm tm_sec As Integer tm_min As Integer tm_hour As Integer tm_mday As Integer tm_mon As Integer tm_year As Integer tm_wday As Integer tm_yday As Integer tm_isdst As Integer End Struct Private Extern localtime(timep As Pointer) As StructTm In "libc:6" --8<----------------------------------------------------------------- A temporary Gambas structure object is allocated each time the localtime() is called. It stores the return value, but it does not copy the structure data, it just points at it. So the pointed structure must not be freed while you are using it! Does it fit your needs? -- Benoît Minisini ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user