user6125029
user6125029

Reputation:

The return type is incorrect

The type is defined:

typedef int (*vlc_media_player_is_playing(libvlc_media_player_t*));

The class defines a field with this type. The field is populated with the address of the function from the dll. When you try to call a function, the int* pointer is returned instead of int. Why is this happening?

Thus, in the pointer are the data correct.

When you try to dereference the pointer, the program crashes.

I will also add that an example of this type:

typedef struct libvlc_instance_t libvlc_instance_t;
typedef libvlc_instance_t(*vlc_create_instance(int, const char* const*));

Somehow, too, returns a pointer at once.

class Foo
{
...
private:
    vlc_media_player_is_playing*    libvlc_media_player_is_playing = nullptr;
...
public:
    Foo()
    {
        libvlc_media_player_is_playing = (vlc_media_player_is_playing*)GetSomeAddress("SomeFuncName");
    }

    void call()
    {
        // but this is not `int`
        int result = libvlc_media_player_is_playing(player_ptr);
    }
}

Upvotes: 0

Views: 87

Answers (1)

Raindrop7
Raindrop7

Reputation: 3911

vlc_media_player_is_playing is an alias to a pointer to a function that returns an integer and takes a pointer to libvlc_media_player_t struct.

So any usage of this type is considered to be a pointer to function eg:

vlc_media_player_is_playing myFunc = SomeFuncReturningIntTakingVlc;

To call the function through the pointer eg:

int ret = (*myFunc)(libvlc_media_player_tParam);

But you created a pointer to a pointer to function here:

 vlc_media_player_is_playing* libvlc_media_player_is_playing = nullptr;

So remove the pointer operator above to make it look like:

vlc_media_player_is_playing libvlc_media_player_is_playing = nullptr;

And to call the function later in your function call:

int result = (*libvlc_media_player_is_playing)(player_ptr);

Upvotes: 2

Related Questions