Possible to pass binaryStream to declare?

Is it possible to pass an open binary stream as a parameter for a declare? I have an extensive library of C routines that I compiled into a dynamically linked library. I am new to declares but have been able to accomplish most of what I have tried so far, however this file access issue has stumped me for several days now despite lots of searching online and trying different things. I have a lot of RB/Xojo experience, but not much with C, so I would prefer to use the library as-is if I can rather than modifying the library (I can modify it if necessary). The declare looks like this:

Soft Declare Sub seekloc Lib dylibLocation (fptr As Ptr, iseek As Integer, mseek As Integer, ByRef lskip As Integer, ByRef ldata As Integer)

The fptr parameter is supposed to be C type FILE, and looks like this in the source code for the library:

void seekloc(FILE *fptr,int iseek,int mseek,int *lskip,int *ldata)

I do not have a good understanding of C file IO routines and types. I have to open the stream and repeatedly call seekloc to read an arbitrary number of large structures from the file and process them one by one. The files can be huge.

Is there a way to do this or do I need to rewrite and/or add to the C library instead? I will be very grateful for any help. Thank you!

Don’t know much about declares. But wouldn’t a simple path be easier to transfer?

The BinaryStream.Handle method returns a platform-specific file handle that can be used with declares.

Thanks much to both of you.

Andrew, I had actually tried using the BinaryStream.Handle yesterday after reviewing the documentation, but it returns an integer and the declare expects a pointer. I tested a few different ways of using the handle but could not get it to run without errors. That was shortly before I started this thread. I will look for examples of using the Handle property online and in the sample projects and see if I can find something to help me understand how all this works.

Beatrix, if the external routines could work with it as a path that would be the way to go, but I need to open the file before I start calling the external routines (declares) unless I modify the C library, which for various reasons I need to avoid unless absolutely necessary.

change your declare to integer.
And make sure you ask for the right handle type.

Thanks much guys, at least I know am on the right track now. I will post more after running tests with a simpler file and code.

Using BinaryStream.Handle did work, I passed it as an integer and retrieved data from the BinaryStream I had opened in Xojo via a declare to the C library. Thank you all again, this was driving me nuts. I am not sure why it did not work yesterday, but I was so mentally fried by the time I tried to use it I am sure I just made some error(s). In case it helps anyone else here is some simple test code I used to get this working (on a Mac). If you experts notice any problems with this code please feel free to speak up, and thanks again!

Dim f As FolderItem
Dim b As BinaryStream
Dim p As Integer
Dim s As CString

Const libLocation = “/path/to/my/library/libtestfileio.dylib”

Soft Declare Function returnFileData Lib libLocation (p As Integer) As CString

f = GetOpenFolderItem("")
b = BinaryStream.open(f, False)
p = b.Handle(binaryStream.HandleTypeFilePointer)

s = returnFileData§

b.Close
MsgBox(s)