Re: The problem with the conversion.

2019-06-19 Thread XavierAP via Digitalmars-d-learn

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);


Re: The problem with the conversion.

2019-06-19 Thread XavierAP via Digitalmars-d-learn

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.


Re: The problem with the conversion.

2019-06-19 Thread drug via Digitalmars-d-learn

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);
}
```