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: meta_db_io Callback Registration (Read 2775 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

meta_db_io Callback Registration

I'm wondering what exactly I have to do to register for callbacks when meta_db entries are modified.

Right now I am doing my testing by modifying the foo_tutorial1 plugin. Based off of how the menu entry is registered and how I saw things being done in foo_httpcontrol, in foo_tutorial1.cpp I added

Code: [Select]
class metadb_io_callback_tutorial1 : public metadb_io_callback_dynamic_impl_base
{
    virtual void on_change_sorted(const pfc::list_base_const_t<metadb_handle_ptr>& p_items_sorted, bool p_fromhook)
    {
        SharedVars::num_callbacks++;
    }
};

static metadb_io_callback_tutorial1 mdb_callback;
static service_ptr_t<metadb_io_v3> mdb_io;


and in on_init() I added:
Code: [Select]
mdb_io->register_callback(&mdb_callback);


This code all compiles just fine, but when I try to run Foobar with the plugin I get this error:
Failed to load DLL: foo_tutorial1.dll
Reason: Invalid access to memory location.

And, even though it says it didn't load the DLL, Foobar crashes when I close it.

meta_db_io Callback Registration

Reply #1
You probably want to use static_api_ptr_t<metadb_io_v3> to access that service. Oh, and I don't know if you can get away with using a static instance of the callback, that may or may not work.

meta_db_io Callback Registration

Reply #2
You probably want to use static_api_ptr_t<metadb_io_v3> to access that service. Oh, and I don't know if you can get away with using a static instance of the callback, that may or may not work.


I made those changes and moved the static_api_ptr_t line inside the oninit function and it is no longer crashing. However, I am not getting callbacks for the events I expected. Since the metadb_handle has a format title function, I thought I would be getting notified whenever a tag updates. Is there a way to get a callback for that or will I have to make a thread that continuously calls format_title on every item in the library until the result changes?