The problem with the conversion.

XavierAP n3minis-git at yahoo.es
Wed Jun 19 17:28:38 UTC 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.


More information about the Digitalmars-d-learn mailing list