Returning Objects from Userlibs

BlitzPlus Forums/BlitzPlus Programming/Returning Objects from Userlibs

turtle1776(Posted 2005) [#1]
In the specifications for Blitz userlibs, which can be found here: http://www.blitzbasic.com/sdkspecs/sdkspecs/userlibs_specs.txt

Mark Sibly says:

Neither Banks or objects can be returned from functions.


However, in my experience with userlibs this is not true. You can get objects back from userlibs by simply creating a bank big enough to receive the data. You then get whatever information you need out of the bank with the various Peek functions.

Two examples of programs that I wrote that do this are in the code archives, including:

FTP Using WinInet Userlib Functions --> look at the FTPGetFileList() function
http://www.blitzbasic.com/codearcs/codearcs.php?code=1444

and

FileDate$() and GetFileTime$() --> look at the GetFileTime() function.
http://www.blitzbasic.com/codearcs/codearcs.php?code=1442

I wonder why that quote was included in the userlib specs? It discouraged me from even playing with userlibs for a long time because I thought they were so limited.


Difference(Posted 2005) [#2]
You are not returning banks from functions.
You are passing them by reference and letting the dll put someting in them.
Then after the dll call, you read what the dll function wrote.

To return a bank from a function, the function would have to create a blitz bank/object, and put it into Blitz internal bank/object lists etc. Since your dll functions can only return normal memory blocks, structs, strings and variables, it's not possible.


turtle1776(Posted 2005) [#3]
Good point.

Peter, if I remember correctly, you wrote a library that accesses OpenGL via Blitz (edit: duh, there it is in your sig), so you have some expertise in this area. I wrote a related Extended2D DirectX wrapper for Blitz2D and B+ a few years back, but have been busy doing other things lately and am a bit rusty.


Difference(Posted 2005) [#4]
Yes I remeber the DirectX wrapper.
There's still a link to the openGl headers in my sig, but now we have BlitzMax :)