Introduction and a question about (VST) .dll hInstance/hModule


#1

Hi Forum, my Name’s Andreas and I’m a developer at brainworx. Besides product development, I also assist our 3rd party program manager in supporting our 3rd party developers within Plugin Alliance.

Some of our current 3Ps use JUCE, which is why I joined this forum.

We recently came across the issue of needing to obtain the hInstance/hModule of the current .dll for integrating code from our framework. In our own plugins, we implement DllMain, which gets the hInstance from the host.

Am I correct in assuming that JUCE handles this via the VST wrapper? Is there a possibility using JUCE functions/data structures to obtain the hInstance of the current DLL? I was only able to give the JUCE framework a cursory glance so far, so it would be great if somebody could point me in the right direction.

I was able to solve the issue using the undocumented hack described in https://blogs.msdn.microsoft.com/oldnewthing/20041025-00/?p=37483 but I`m wondering if JUCE offers a better (i.e. more “official”) way to accomplish this?

Best regards
Andreas Schröder


#2

How about Process::getCurrentModuleInstanceHandle() ?


#3

Thanks Jules, just checked the implementation to see if that’s what I was looking for, but apparently that only works if currentModuleHandle is set, i.e. if setCurrentModuleInstanceHandle is called (in DllMain). Does the VST wrapper take care of that?


#4

This is the DllMain in the VST 2 wrapper (VST 3 looks to have the same implementation as well).

extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID)
{
    if (reason == DLL_PROCESS_ATTACH)
        Process::setCurrentModuleInstanceHandle (instance);

    return true;
}

#5

Thanks a lot Jules and Anthony, I tried it in the demo project I got from our 3P and it works (of course :slight_smile:) I’ll validate that this fixes our 3Ps problem and let you know, but from all I’ve seen so far I’m convinced that it will.

Best regards,
Andreas


#6

I forgot to mention it, but of course, that did indeed solve the problem we were having, so thanks again for the help.

Best regards,
Andreas