Author Topic: BASS_ChannelGetData returns a DWORD, but also -1?  (Read 135 times)

ManlioMZ

  • Posts: 23
I ran into some problems testing the BASS library in Lazarus pascal, because BASS_ChannelGetData returns a result in DWORD format, but the documentation says that in case of errors, the result is -1.

Now, DWORD (at least in Pascal) is an unsigned number, and cannot be -1.

Therefore if I read the result of BASS_ChannelGetData with a DWORD variable, and check for a -1 result, I will never get it!

I solved it by using a signed integer, instead of DWORD, to store the result of the BASS_ChannelGetData call. Alternatively, I check that the unsigned returned number of bytes/samples is within the expected range.

Anyway, problem solved for me, but I thought to let everyone know about this situation. Something similar may also happen with other functions that return DWORD and represent errors with -1


Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: BASS_ChannelGetData returns a DWORD, but also -1?
« Reply #1 on: 19 Jul '24 - 16:28 »
-1 is an integer with all bits set, so the same as FFFFFFFF hex (or FFFFFFFFFFFFFFFF for 64-bit values) but less typing. For Pascal/Delphi, there's a DW_ERROR constant (and QW_ERROR for 64-bit) defined in BASS.PAS that you can use instead. Using "not 0" may also work.

ManlioMZ

  • Posts: 23
Re: BASS_ChannelGetData returns a DWORD, but also -1?
« Reply #2 on: 19 Jul '24 - 16:43 »
Thanks, understood. Please note however that "not zero" will not work when I depend on the result of the function to know how many bytes/samples I have received from a call to BASS_ChannelGetData. In that case the non-zero value is the amount of received data, and only the special non-zero case of xFFFFFFFF indicates an error.

Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: BASS_ChannelGetData returns a DWORD, but also -1?
« Reply #3 on: 19 Jul '24 - 17:26 »
I'm not a Pascal/Delphi user myself, so I haven't tried it to confirm, but the "not" keyword can apparently be a logical "not" or a bitwise "not". A bitwise "not 0" will result in -1 (FFFFFFFF). I'm not sure whether "not 0" will work in 64-bit comparisons too or if you would need to modify for that, perhaps "not int64(0)"? May be safest to just stick with the DW_ERROR and QW_ERROR constants.

   https://www.delphibasics.co.uk/RTL.php?Name=Not