JUCE Way of loading DynamicLibrary Functions?


#1

Hi JUCE community!!

I have a custom dyLib/dll I’d like to load in the constructor of my plugin. My questions are included in the comments:

// Built using Projucer Dynamic Library Project

// MyDyLib.h
#pragma once

int getInt();

// MayDyLib.c (showing Mac version)
// via Apple's Developer guide on making/using dynamic libraries
// compiled with -fvisibility=hidden
#include "MyDyLib.h"

#define EXPORT __attribute__((visibility("default")))

EXPORT
int getInt() { return 12345; }

// MyAudioProcessor.cpp
#include "MyDyLib.h"
// MyAudioProcessor::MyAudioProcessor()
    DynamicLibrary dll;
    auto res = dll.open ("myDyLib");
    if (res)
    {
        // what's the "JUCE" way to load the function addresses as defined in myDyLib's header file MyDyLib.h?
        auto func = (dll.getFunction ("getInt"));
        if (func != nullptr)
        { 
            // I've gotten to this point but I'm not sure what the cleanest/most portable method of casting to MyDuLib's getInt() function is
        }
    }

If anybody has some general dll advice, also, that’d be rad. I’m not planning on using classes as I’ve heard that’s tough to get straight. And I’m trying to reduce platform specific implementation as much as possible. I’m looking for a solution that would support 32/64 bit plugins on macOS/Windows.

Many thanks in advanced for the help!

RP


#2

The DynamicLibrary class is what you want: https://www.juce.com/doc/classDynamicLibrary


#3

Check out the code I gave. I’m aware of and using DynamicLibrary! :slight_smile: