Oddly enough after all these years I’ve never needed to declare but that all changes today. I’m doing something with the BASS audio library, and I’ve got a sample file from these forums so I’m all good and it does load the BASS dylib.
How do I convert the “char *url” to Xojo speak. I’ve tried MemoryBlocks, CString, CFStringRef etc. and been extremely good at crashing my app.?
This is a sample of one of my tests etc (kLibBass is declared and does work as I’m just adding to a known working sample)
Declare Function BASS_CreateStreamFromURL Lib kLibBass ( _
url As CString, _
offset As UInt32, _
flags As UInt32, _
proc As Ptr, _
void As Ptr _
) As Ptr
ah I love char * and unsigned char * when thy occur in C headers
Often C folks would use “char *” to mean "ptr to a c terminated string but it CAN also be “bunch of bytes” and you dont know which
You can only really tell “the right thing to pass” from usage and since you dont have the BASS library source code that parameter SEEMS to be a string so just use “string” and Xojo will do the right thing
Declare Function BASS_CreateStreamFromURL Lib kLibBass ( _
url As String, _
offset As UInt32, _
flags As UInt32, _
proc As Ptr, _
void As Ptr _
) As Ptr
[quote=312423:@]says that URL will be UTF-8 on a mac, which is 4 bytes per character, so that should be a WString, not a CString.
[/quote]
UTF-8 is definitely not 4 bytes per character. It is a variable length encoding.
Some code points require 1 bytes (those that are the same as ASCII) and some can require many more.
UTF-16 is usually represented identically to UCS2, or 2 bytes per character, but then it has some other interesting characteristics.
[quote=312368:@Norman Palardy]ah I love char * and unsigned char * when thy occur in C headers
Often C folks would use “char *” to mean "ptr to a c terminated string but it CAN also be “bunch of bytes” and you dont know which
You can only really tell “the right thing to pass” from usage and since you dont have the BASS library source code that parameter SEEMS to be a string so just use “string” and Xojo will do the right thing
Declare Function BASS_CreateStreamFromURL Lib kLibBass ( _
url As String, _
offset As UInt32, _
flags As UInt32, _
proc As Ptr, _
void As Ptr _
) As Ptr
[/quote]
Thanks. I had to use CString. Using String gave me a “External functions cannot use ordinary strings as parameters… etc.”.
[quote=312423:@]Let us know how you get on and I’ll add it to http://blog./2017/01/22/windows-to-xojo-data-type-conversion/ even though this is a mac thread
After looking at the manual
says that URL will be UTF-8 on a mac, which is 4 bytes per character, so that should be a WString, not a CString.
If you could try String and WString and let us know how you get on I’d be very interested.[/quote]
CString seems to be fine on my Mac. That said I didn’t make any changes to encoding, just BASS as it comes out of the box and -1 (for default device in BASS_init.