Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3617712
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:39:34+00:00 2026-05-18T22:39:34+00:00

In Delphi XE I am using the BASS audio library , which contains this

  • 0

In Delphi XE I am using the BASS audio library, which contains this function:

function BASS_StreamCreateURL(url: PAnsiChar; offset: DWORD; flags: DWORD; 
    proc: DOWNLOADPROC; user: Pointer):HSTREAM; stdcall; external bassdll;

The ‘url’ parameter is of type PAnsiChar, so in my code I do a cast:

FStreamHandle := BASS_StreamCreateURL(PAnsiChar( url ) [...]

The compiler emits a warning on this line: “suspicious typecast of string to PAnsiChar”. In trying to eliminate the warning, I found that the recommended way is to use a double cast:

FStreamHandle := BASS_StreamCreateURL(PAnsiChar( AnsiString( url )) [...]

This does eliminate the warning, but the BASS function now returns error code 2 (“cannot open file”), which tells me the URL string it receives is somehow broken. I cannot see what the bass DLL actually receives, but using a breakpoint in the debugger the string looks good:

var
  s : PAnsiChar;
begin
  s := PAnsiChar( AnsiString( url ));

At this point string s appears fine, but the BASS function fails when I pass it. My initial code: PAnsiChar( url ) works well with BASS, but emits a warning.

So what’s the correct way of getting from UnicodeString to PAnsiChar without a warning?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:39:35+00:00Added an answer on May 18, 2026 at 10:39 pm

    I am amazed that

    BASS_StreamCreateURL(PAnsiChar( url ) [...]
    

    works. If url is a unicode string, each character will occupy two bytes. If, for instance, the string is test, it will read

    7400 6500 7300 7400 0000                t e s t #0                     (Unicode)
    

    in memory. Notice that the string ends at the null character (0000) When you do

    PAnsiChar(url)
    

    you will tell the compiler that the memory at this address should be thought of as an AnsiString. But if you consider the above sequence of bytes, you will find only “t” in this case. Indeed, as an AnsiString, the sequence should be interpreted as

    74 00 65 00 73 00 74 00 00 00           t #0 e #0 s #0 t #0 #0 #0      (Ansi)
    

    which is the string “t”, ending with the null character (00).

    PAnsiChar(AnsiString(url))
    

    on the other hand will first convert the unicode string to an ansi string, that is, you will obtain

    74 65 73 74 00                           t e s t #0                    (Ansi)
    

    which is the string “test” ending with the null character (00).

    Update

    I am not psychic (yet), but maybe the Bass library actually does require a pointer to a UnicodeString as the first argument to this function? That would explain why the seemingly odd

    PAnsiChar(url)
    

    works. The library might say “Hey, just give me the pointer to the unicode string, and I’ll do some manual processing with it” and the code above does just that (a pointer is just a pointer (that is, an unsigned 32 bit integer)…). But the compiler will complain, of course, because the library explicity told the compiler that it will require a PAnsiChar, and normally PAnsiChar(SomeUnicodeString) is bad. If this is the case, of course, then,

    PAnsiChar(AnsiChar(url))
    

    doesn’t work. The library expects /the address of/ a unicode string, but gets /the address of/ an ansi string.

    Update 2

    If my hypothesis in Update 1 is correct, the declaration

    function BASS_StreamCreateURL(url: PWideChar; offset: DWORD; flags: DWORD; 
        proc: DOWNLOADPROC; user: Pointer):HSTREAM; stdcall; external bassdll;
    

    would make the skies blue again.

    Update 3

    From the documentation:

    NOTE: Delphi 2009 users should use the BASS_UNICODE flag where possible

    I bet that the problem will go away if you specify this flag when you call BASS_StreamCreateURL!

    From the sample unit Main.pas:

    Channel := BASS_StreamCreateFile(FALSE, PChar(OpenDialog.FileName), 0, 0,
        0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By using Delphi 5, can I call a function in web service which is
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
I am using Delphi TApplication.OnException Event to catch unhandled exceptions This works well but
Using Delphi, I need a function to evaluate the current date and see if
Using Delphi 7, I wonder if there is a free component which will collect
Using Delphi 2010, let's say I've got a class declared like this: TMyList =
Using Delphi, how do I access the equivalent of .NET's System.Environment.SpecialFolder.LocalApplicationData variable (which works
I'm using Delphi XE and I would like to make a button which shows
Using Delphi XE on Win7 x64, have Jedi Class Library ver. 3.45, and 7z.dll
I'm using Delphi 6 and I've got an application which when being shut down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.