weave
New Member
Posts: 5
|
Post by weave on Apr 7, 2011 9:14:42 GMT 1
Hello, I'm a novice trying to understand how to create an interface and I'm having trouble with structures and pointers to structures. I have no experience with C/C++ so that could be why I'm struggling. I couldn't find a tutorial so I have been looking at mysql.bac and the MySQL C api reference here: dev.mysql.com/doc/refman/5.0/en/c-api-functions.html and trying to figure it out what to do from those but I'm afraid I need someone to help me understand. At first glance I thought all I had to do was pass a long wherever a pointer was required and that made sense to me because I thought the long would contain the memory address of whatever was being pointed to but then I noticed this: IMPORT "mysql_fetch_row(long)" FROM mysql_LIB$ TYPE long* where the C function is defined as: MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)and then this: IMPORT "mysql_fetch_fields(long)" FROM mysql_LIB$ TYPE long* this function in the MySql reference is defined like as: MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *result)If my limited understanding of C is correct doesn't the definition MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)return a structure and MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *result) return a pointer to a structure? And if I'm right about that how come the return value in BaCon is defined the same way for both functions, i.e. long*? Also would Uint32 be declared as int or long? Thanks to anybody who can bring clarity to my cloudy brain.
|
|
|
Post by Pjot on Apr 7, 2011 12:17:10 GMT 1
Well I wouldn't know that; where did you get your IMPORT examples from? On the BaCon website you'll find a MySQL interface which does not use these functions. If a function returns a struct then forget about importing it. Because the resulting memory pointer should be typedef'ed to obtain its members and this can not be done with BaCon statements. (Theoretically it is possible with a USEC/ENDUSEC construct, after which an explicit link with the MySQL library is needed.) The type 'Uint32' means "unsigned int of 4 bytes", you could declare it as int. Best regards Peter
|
|
weave
New Member
Posts: 5
|
Post by weave on Apr 7, 2011 13:16:40 GMT 1
Hello Peter, Well I wouldn't know that; where did you get your IMPORT examples from? I took the examples from this file: www.basic-converter.org/mysql.bac.htmlOn the BaCon website you'll find a MySQL interface which does not use these functions. It's not so much that I want to use MySQL, I want to learn how to create an interface and I was using the MySQL one as an example. I was hoping to create a BaCon interface for SDL but many of the functions receive and return pointers to structures and I really want to understand how I handle that. Thanks.
|
|
|
Post by Pjot on Apr 7, 2011 14:26:42 GMT 1
Hi weave,
Ah I see! This is an old import file and may not have all functions correctly defined.
Basically importing functions comes down to define their prototype to known C types. A lot of header files and external libraries use their own types so it may be hard to find out how to import them.
In all cases I would use 'long' for pointer types. For types like 'uint32' or 'bool' I would use 'int'.
If there are structs as a type or as returntype: too bad, these cannot be casted.
Sometimes you simply need to try and test.
Note that the target library always needs to be programmed in plain C (and not C++) otherwise an IMPORT is not possible anyway.
Best regards Peter
|
|