Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Compiler errors! (Read 3195 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Compiler errors!

Hi!
I'm using Visual C++ 2005 Express Edition + Platform SDK (core components only).
I've created something like:
Code: [Select]
#include "../SDK/foobar2000.h"

class foo_something : public playlist_callback
{
public:
    virtual void on_items_added(t_size p_playlist,t_size p_start, const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const bit_array & p_selection)
    {
        //do something
    }

    virtual void on_items_reordered(t_size p_playlist,const t_size * p_order,t_size p_count) {}
    virtual void on_items_removing(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {}
    ..........
        ..........
};

static service_factory_single_t<playlist_callback, foo_something> foo;

DECLARE_COMPONENT_VERSION("Something", "1.0", "");


and compiler says:
Code: [Select]
.\foo_something.cpp(33) : error C2977: 'service_factory_single_t' : too many template arguments
        csee declaration of 'service_factory_single_t'
.\foo_something.cpp(33) : error C2133: 'foo' : unknown size
.\foo_something.cpp(33) : error C2512: 'service_factory_single_t' : no appropriate default constructor available


What am i doing wrong? 

Compiler errors!

Reply #1
service_factory_single_t only takes one argument. Just use
Code: [Select]
static service_factory_single_t<foo_something> foo;


Edit: Please also have a look at the SDK readme. Somehow I get the impression that you must have missed it.

Compiler errors!

Reply #2
If I do it with one argument I get:
Code: [Select]
d:\sdk\foobar2000\sdk\service.h(376) : error C2039: 't_interface_entrypoint' : is not a member of 'foo_something'
        .\foo_something.cpp(3) : see declaration of 'foo_something'
        .\foo_something.cpp(33) : see reference to class template instantiation 'service_factory_single_t<T>' being compiled
        with
        [
            T=foo_something
        ]
d:\sdk\foobar2000\sdk\service.h(376) : error C2146: syntax error : missing ',' before identifier 't_interface_entrypoint'
d:\sdk\foobar2000\sdk\service.h(376) : error C2065: 't_interface_entrypoint' : undeclared identifier
d:\sdk\foobar2000\sdk\service.h(376) : error C2955: 'service_factory_base_t' : use of class template requires template argument list
        d:\sdk\foobar2000\sdk\service.h(243) : see declaration of 'service_factory_base_t'


Any thoughts? I just want to implement a playlist_callback... 

Compiler errors!

Reply #3
playlist_callback is not a service entrypoint class (it does not derive from service_base). Use playlist_callback_static or register your callback dynamically.

Compiler errors!

Reply #4
Looks like you're doing it the 0.8 way.

Take a look at playlist.h. 0.9 has the ability to dynamically register callbacks, which is what playlist_callback is for. If you scroll a bit down you'll see a playlist_callback_static subclass which is probably what you want.

The difference is that the _static class is a service, and has an entrypoint macro at the end which allows it to be used with a service_factory class like you want. Additionally, a playlist callback needs some flags that tell foobar which events to respond to. Because you can't tell foobar which flags those are when registering (it's always autoregistered for you when the plugin is loaded), you'll also need to implement the get_flags method.

Eventually, your code should look something like this:
Code: [Select]
#include "../SDK/foobar2000.h"

class foo_something : public playlist_callback_static
{
public:
    virtual void on_items_added(t_size p_playlist,t_size p_start, const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const bit_array & p_selection)
    {
        //do something
    }

    virtual void on_items_reordered(t_size p_playlist,const t_size * p_order,t_size p_count) {}
    virtual void on_items_removing(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {}
    ..........
        ..........
    virtual unsigned get_flags()
    {
        return flag_on_items_added;
    }
};

static service_factory_single_t<foo_something> foo;

DECLARE_COMPONENT_VERSION("Something", "1.0", "");

Compiler errors!

Reply #5
Thank you very much! I figured it out just before i saw your posts, but your explanations were great!