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: Basic questions on service instantiation and templates (Read 5292 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Basic questions on service instantiation and templates

Hi, I just started with component developing and I have some  questions/problems.

I decided I would try to make a plugin that would simply spam the console, but I don't understand how I should instance/tell foobar that it should call my class that inherits from main_thread_callback. My code looks like this:
Code: [Select]
#include "SDK\foobar2000.h"
#pragma comment (lib,"shared.lib")


DECLARE_COMPONENT_VERSION("foo_sample","7.77","Yup, working!");

class Foo_sample: public main_thread_callback
{
public:
    virtual void callback_run();
};

void Foo_sample::callback_run()
{
    console::print("Hey?");

}

class iq : public initquit {
    virtual void on_init()
    {
        console::print("foo_sample says hello!");
    }

};

static initquit_factory_t<iq> inst_iq;


Next question is how I can use inst_iq to do things.

Thanks.
I just like listening to music

Basic questions on service instantiation and templates

Reply #1
You need to use the main_thread_callback_manager service through a static_api_ptr_t to add_callback your main_thread_callback implementation.

Code: [Select]
service_ptr_t<main_thread_callback> p = new service_impl_t<Foo_sample>;
static_api_ptr_t<main_thread_callback_manager>()->add_callback(p);
Stay sane, exile.

Basic questions on service instantiation and templates

Reply #2
Thanks, I'll come back with more questions later since I find all this template and service stuff confusing (to be fair I haven't worked very much with templates, should maybe give myself a crash course a bit further in the subject).

For example, how do I know if to create a static api pointer or a service pointer?
I just like listening to music

Basic questions on service instantiation and templates

Reply #3
From the SDK documentation (just the brief comment):
Quote
Helper template used to easily access core services.

Quote
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.