String to byte ptr ?

BlitzMax Forums/BlitzMax Programming/String to byte ptr ?

Filax(Posted 2005) [#1]
Hi :)

I have try to convert an old bmax source code with the new
version 1.10 but the program crash on this line

B.Stream=BASS_StreamCreateFile(0,File,0,0,B.MusicFlag|BASS_MP3_SETPOS)

Error : "Unable to convert from string to byte ptr"

I think that the FILE arg is the cause (it's a string) but
i don't know how solve this problem ? me and the pointer ...

But the BASS DLL function calling nee byte ptr :
Global BASS_StreamCreateFile(mem:Int, file:Byte Ptr, offset:Int, length:Int, flags:Int)"Win32" = GetProcAddress(DllHandle,"BASS_StreamCreateFile")


Kev(Posted 2005) [#2]
filax, try this.

Local file$ = "c:test\test.exe"
Local file_str_pointer:Byte Ptr = Byte Ptr file$


Filax(Posted 2005) [#3]
Hi Kev

Your source generate the same error ! i don't know why !


Kev(Posted 2005) [#4]
the small example compiles fine here, try.

Local file:String = "c:test\test.exe"
Local file_str_pointer:Byte Ptr = Byte Ptr file


Filax(Posted 2005) [#5]
The solution is : ToCString()

Local File_Pointer:Byte Ptr=File.ToCString()
B.Stream=BASS_MusicLoad(0, File_Pointer, 0, 0,B.MusicFlag,0)


Kev(Posted 2005) [#6]
hey filax i dont see the new beta 1.11? is it not available yet?


Filax(Posted 2005) [#7]
In another section.


Kev(Posted 2005) [#8]
i dont filax, but thanks.


Hotcakes(Posted 2005) [#9]
filax, you're not supposed to let people know that area exists. =]


Filax(Posted 2005) [#10]
Sure but ... it's not armaggeddon :) people cannot go there.


tonyg(Posted 2005) [#11]
...but people will now *want* to go there!


marksibly(Posted 2005) [#12]
Hi,

Ok, shouldn't really be talking about this here but a heads up wont hurt...

The next release of Max will no longer automatically convert strings to Byte Ptr's - you need to explicitly call ToCString...

Local p:Byte Ptr=mystring.ToCString()
...do stuff with p...
MemFree p

...Note the MemFree after you've finished with the Byte Ptr.

The reason for this is that with automatic GC you can't predict when such 'automatic cstrings' may be reclaimed, so I decided to take them out of the GC loop altogether.


Filax(Posted 2005) [#13]
Ok mark thanks ! to clarify.

Sorry for ... shut !!

But i did not think that this problem of programming was specific to the
beta 1.11, if not, I would have posted aillor, afflicts for the mistake.