Page 1 of 1

Unable to use file commands in v6

Posted: Wed Dec 04, 2024 4:18 pm
by TwilCynder
Hello ! Been using PB 5.72 until recently, and after upgrading I've been having a weird issue : I can't open files at all.

OpenFile and Reafile will always return a non-null value, regardless of whether the file exists, and then any file-reading function (including Eof) will crash with "The specified #File is not initialized".
This is happening with all versions starting with 6.0.0, same code works fine in 5.72, and tested on multiple computers, including one where all installs are fresh.

Is there something I'm missing ?

Code example I tested with just in case, but this happens with my existing projects as well

Code: Select all

file.l = OpenFile(#PB_Any, "C:\msys64\ucrt64.ini") ; Using this file because it was the first very short path that came to mind, tested with other various files
Debug file ;will always display a non-null value
If Not file
  Debug "404"
  End
Endif

ReadString(file, #PB_UTF8, 20) ;Will crash here, apparently the file is not initialized ; tested with other functions, including Eof

Re: Unable to use file commands in v6

Posted: Wed Dec 04, 2024 4:20 pm
by Quin
The problem is that you're storing the value in a long, not an integer. If you're on 64-bit, the value is most likely larger than can fit in a long. Change it to .i and all should work as expected.

Re: Unable to use file commands in v6

Posted: Wed Dec 04, 2024 4:22 pm
by TwilCynder
Thank you, that was indeed it ! No idea why I decided to use longs for file handles in the first place now that I think about it

Re: Unable to use file commands in v6

Posted: Wed Dec 04, 2024 5:10 pm
by Kiffi
Additional tip: If you only want to read from a file, it is better to use ReadFile().