Skip to main content

Notice

Please be aware that much of the software linked to or mentioned on this forum is niche and therefore infrequently downloaded. Lots of anti-virus scanners and so-called malware detectors like to flag infrequently downloaded software as bad until it is either downloaded enough times, or its developer actually bothers with getting each individual release allow listed by every single AV vendor. You can do many people a great favor when encountering such a "problem" example by submitting them to your AV vendor for examination. For almost everything on this forum, it is a false positive.
Topic: Basic questions on service instantiation and templates (Read 4787 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);
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.

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.

 
SimplePortal 1.0.0 RC1 © 2008-2021