String Pointer in Declare..

Hi,

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.

I’m experimenting by calling another routine.

HSTREAM BASS_StreamCreateURL( char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user );

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

Any guidance appreciated.

Thanks

I think I may have an answer for you from my own plugin development. I’m at work at the moment. Will have to wait another 4 hours.

Cheers
Grant

Skimming the docs suggests that you have to call BASS_Init to initialize the library before other functions can be used.

Thanks for replies.

BASS_Init was called. It was even more stupid than that :slight_smile:

Slaphead moment.

The actual call us BASS_StreamCreateURL NOT what I somehow mentally modified in my head.

Now we’re cruising. Wood from the tree’s and all that!

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

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 :slight_smile:

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=312423:@JulianS]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.

Ah ok, thanks Norman. good to know. I’ll amend my list, cheers.

[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.”.

Great tip though

[quote=312423:@JulianS]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 :slight_smile:

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.

Trying WString gives me BASS_ERROR_ILLPARAM, CString plays nice. :slight_smile: