Thread overview
The problem with the conversion.
Jun 19, 2019
Den_d_y
Jun 19, 2019
drug
Jun 19, 2019
XavierAP
Jun 19, 2019
XavierAP
June 19, 2019
Hello, users of this programming language! I have a question. I use in my application Derelict SDL 2 version 2.1.4.
And when I try to specify the path to the image:

void load (const (char *) path)
{
    SDL_Surface ab = SDL_LoadBMP (path);
    a = SDL_CreateTextureFromSurface (ab);
    SDL_FreeSurface (ab);
}

An error occurs:
"function derelict.sdl2.functions.SDL_LoadBMP (const (char) * file) is not callable using argument types (string)".
Well, okay, I use in arguments: const (char *) path. Annoyed, the program still writes this error. Please help with this problem.
 P.S. If you see errors in spelling and stuff, then note: I am a Russian user.
  P.P.S. I am not familiar with this programming language.
June 19, 2019
19.06.2019 17:52, Den_d_y пишет:
> void load (const (char *) path)
> {
>      SDL_Surface ab = SDL_LoadBMP (path);
>      a = SDL_CreateTextureFromSurface (ab);
>      SDL_FreeSurface (ab);
> }

try the following:
```
void load (string path)
{
    import std.string : toStringz;
    SDL_Surface ab = SDL_LoadBMP (path.toStringz); // toStringz converts string to null terminated char*
    auto a = SDL_CreateTextureFromSurface (ab);
    SDL_FreeSurface (ab);
}
```
June 19, 2019
On Wednesday, 19 June 2019 at 14:58:44 UTC, drug wrote:
> 19.06.2019 17:52, Den_d_y пишет:
>> void load (const (char *) path)
>> {
>>      SDL_Surface ab = SDL_LoadBMP (path);
>>      a = SDL_CreateTextureFromSurface (ab);
>>      SDL_FreeSurface (ab);
>> }
>
> try the following:
> ```
> void load (string path)
> {
>     import std.string : toStringz;
>     SDL_Surface ab = SDL_LoadBMP (path.toStringz); // toStringz converts string to null terminated char*
>     auto a = SDL_CreateTextureFromSurface (ab);
>     SDL_FreeSurface (ab);
> }

Also, the return type of SDL_LoadBMP is a pointer, SDL_Surface* not just SDL_Surface.

Indeed, in your code do use the D string path, not char*, and use toStringz when passing to C APIs.

Also, in D const(char)* would not be the same as const(char*). But don't worry about this and use string.
June 19, 2019
On Wednesday, 19 June 2019 at 17:28:38 UTC, XavierAP wrote:
>
> Also, the return type of SDL_LoadBMP is a pointer, SDL_Surface* not just SDL_Surface.

Or just use auto of course if you prefer:

void load (string path)
{
    import std.string : toStringz;
    auto ab = SDL_LoadBMP (path.toStringz);