24 May '13 - 17:05 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: BASS_CHANNELINFO.filename strangely mangled!  (Read 593 times)
yegor
Posts: 4


« on: 23 Nov '11 - 20:18 »
Reply with quoteQuote

Hello!

I am writing a webradio app in Delphi2010 and (though this may seem surprising to many) bass.dll is at its very core. First of all I would like to thank the developers for this wonderful piece of software!

I have encountered a very strange problem, though... after getting BASS_CHANNELINFO like this:

if not BASS_ChannelGetInfo(Channel, &ChInfo) then ShowMessage('nothing to do, sorry');

I then try to retrive the name of the file being played (BASS_CHANNELINFO.filename^). If I retreive it as AnsiString, some of the letters seem to have been lost somewhere somehow: the string
always begins with
'ht:'
instead of
'http:'
, and the rest of the string also misses lots of letters. If I try to retrieve it as a WideString, it's even worse... What may be the problem here? Can it be solved? I would greatly appreciate any suggestions, thanks.
Logged
Bert B.
Posts: 103


« Reply #1 on: 24 Nov '11 - 09:00 »
Reply with quoteQuote

Have you defined filename as PChar?

  BASS_CHANNELINFO = record
    freq: DWORD;        // default playback rate
    chans: DWORD;       // channels
    flags: DWORD;       // BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags
    ctype: DWORD;       // type of channel
    origres: DWORD;     // original resolution
    plugin: HPLUGIN;    // plugin
    sample: HSAMPLE;    // sample
    filename: PChar;    // filename
  end;
Logged
yegor
Posts: 4


« Reply #2 on: 24 Nov '11 - 14:40 »
Reply with quoteQuote


Bert,

that's how I try to get it as an AnsiString:

var
A: PChar;
  AStr: AnsiString;
begin
  if not BASS_ChannelGetInfo(Channel, &ChInfo) then (* ... *)
  else
  begin
    AStr := '';
    A := ChInfo.filename;
    while A^ <> #0 do
      begin
        AStr := AStr + AnsiChar(A^);
        Inc(A);
      end;

And the filename ALWAYS begins with 'ht:/' instead of 'http:/' , and the rest of the string is also very funny.
Logged
3delite
Posts: 623


« Reply #3 on: 24 Nov '11 - 16:23 »
Reply with quoteQuote

That's not right!

A PChar is 2 bytes long (in Delphi 2010 unicode), so you increment it by 2 bytes with Inc(A) and get every second character.
Try to define A as PAnsiChar.
Logged
yegor
Posts: 4


« Reply #4 on: 24 Nov '11 - 17:12 »
Reply with quoteQuote

You seem to be right! Thank you!

But now the problem is that the compiler tells me BASS_CHANNELINFO.filename is a PWideChar and cannot be assigned to A if A is defined as PAnsiChar.
Logged
3delite
Posts: 623


« Reply #5 on: 24 Nov '11 - 18:31 »
Reply with quoteQuote

Try:

    A := PAnsiChar(ChInfo.filename);
Logged
Bert B.
Posts: 103


« Reply #6 on: 25 Nov '11 - 07:49 »
Reply with quoteQuote

The following just works:

var
  AStr: String;
begin
  if not BASS_ChannelGetInfo(Channel, &ChInfo) then (* ... *)
  else
  begin
    AStr := ChInfo.filename;
  end;
Logged
yegor
Posts: 4


« Reply #7 on: 25 Nov '11 - 15:14 »
Reply with quoteQuote

@3delete: Thank you a thousand times! It does!

@Bert: Sorry, it does not.
Logged
Bert B.
Posts: 103


« Reply #8 on: 28 Nov '11 - 08:45 »
Reply with quoteQuote

When using Delphi 2009 or higher, you should AnsiString wherever possible.
Do you use the flag BASS_UNICODE in the call to BASS_StreamCreateFile?
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines