Creating Basic DLL From Juce Application


#1

I am a complete C++ novice and was trying to get the audio plugin host demo into a dll instead of an application. This is because the interface to an Adobe AIR app I am creating requires a DLL format. I have looked at the VST Wrapper class and it is a little over my head.
All I really need is to see, is a very basic example of a very simple Juce app in DLL form and a Juce app that uses that DLL

To that end, I have spent about three days trying to do it myself and about three hours scouring the forums for anything useful.

If anybody can provide the most basic of examples, I would greatly appreciate it.

Thanks,
Josh


#2

Essentially, you just need to drop all the JUCEApplication stuff, and instead make sure you call initialiseJuce_GUI() before using any juce classes. As long as your host app is running a normal event loop, you should be ok.

You say you’ve been trying for 3 days, which sounds like you’re in a bit of a muddle… it’s really shouldn’t be that difficult. Maybe try asking us some more detailed questions about what isn’t working for you?


#3

In VC++ Express 10, I have taken the plugin host demo and set it to compile as a DLL and removed the precompiled header entries from the properties of the VC++ 2010 build.
I added a HostStartup.h file with the following code:

#include <Windows.h>
namespace TestDll
{
	extern "C" class TestDllClass
	{
		static __declspec( dllexport ) int startUp() ;
		static __declspec( dllexport ) int shutDown();
		static __declspec( dllexport ) BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID);
	};
}

Then in the HostStartup.cpp, I have commented out the, “START_JUCE_APPLICATION (PluginHostApp);” line and added the following:

namespace TestDll
{
    extern "C" int TestDllClass::startUp()
    {
        initialiseJuce_GUI();
		return 1;
    }

    extern "C" int TestDllClass::shutDown()
    {
        shutdownJuce_GUI();
		return 2;
    }
}

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

    return TRUE;
}

We get the following errors when we try to build it:
1> HostStartup.cpp
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : '('
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2090: function returns array
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1212): error C2143: syntax error : missing ‘;’ before ''
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2047): error C2143: syntax error : missing ‘;’ before '
'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2057): error C2143: syntax error : missing ‘;’ before 'identifier’
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2057): warning C4091: 'typedef ’ : ignored on left of ‘_M128A’ when no variable is declared
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2057): fatal error C1075: end of file found before the left brace ‘{’ at ‘c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(28)’ was matched
1> InternalFilters.cpp

Any help would be much appreciated.


#4

[quote=“joshbabier”][quote=“jules”]
Essentially, you just need to drop all the JUCEApplication stuff, and instead make sure you call initialiseJuce_GUI() before using any juce classes. As long as your host app is running a normal event loop, you should be ok.

You say you’ve been trying for 3 days, which sounds like you’re in a bit of a muddle… it’s really shouldn’t be that difficult. Maybe try asking us some more detailed questions about what isn’t working for you?
[/quote]

In VC++ Express 10, I have taken the plugin host demo and set it to compile as a DLL and removed the precompiled header entries from the properties of the VC++ 2010 build.
I added a HostStartup.h file with the following code:

#include <Windows.h>
namespace TestDll
{
	extern "C" class TestDllClass
	{
		static __declspec( dllexport ) int startUp() ;
		static __declspec( dllexport ) int shutDown();
		static __declspec( dllexport ) BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID);
	};
}

Then in the HostStartup.cpp, I have commented out the, “START_JUCE_APPLICATION (PluginHostApp);” line and added the following:

namespace TestDll
{
    extern "C" int TestDllClass::startUp()
    {
        initialiseJuce_GUI();
		return 1;
    }

    extern "C" int TestDllClass::shutDown()
    {
        shutdownJuce_GUI();
		return 2;
    }
}

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

    return TRUE;
}

We get the following errors when we try to build it:
1> HostStartup.cpp
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : '('
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2090: function returns array
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1212): error C2143: syntax error : missing ‘;’ before ''
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2047): error C2143: syntax error : missing ‘;’ before '
'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2057): error C2143: syntax error : missing ‘;’ before 'identifier’
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2057): warning C4091: 'typedef ’ : ignored on left of ‘_M128A’ when no variable is declared
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(2057): fatal error C1075: end of file found before the left brace ‘{’ at ‘c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(28)’ was matched
1> InternalFilters.cpp

Any help would be much appreciated.[/quote]

Oh and here is a link to the project: http://www.mediafire.com/?mv2sdxo12h6cf0s

Thanks again.


#5

The errors are because you’re using an old version of juce that defines the T macro, and are including windows.h after juce.h. Either get an up-to-date version of juce (I’ve got rid of the old T macro now), or just include windows.h before you include juce.

And your code looks pretty garbled… anything that’s declared as extern “C” cannot have a namespace, or be a method, it has to just be a plain C function.


#6

We are using version 1.54.27 is that not the latest version?


#7

No, it’s not, but don’t worry about that, just do what I suggested about the order of include files.


#8

So I was able to compile the dll after switching the order of Windows.h include.

Then I went on to create a windows app to load the dll. I built it using VC++'s default window app and added in calls to the dll’s startUp and shutDown methods, which in turn call the initialiseJuce_GUI() and shutdownJuce_GUI(), respectively.
The windows app loads the dll and I get the DBG traces for the startUp and shutDown methods but I don’t see any window besides the window of the default window app - no Juce window. There doesn’t seem to be any way that I can actually access the PluginHostApp class or any of it’s methods.

In DllCaller.cpp, I call the startUp method on line 123 and the shutdown method on lines 157 & 171.

You can download the project here: http://www.mediafire.com/?csk1bshgdp4xstb

You can load both projects from the “audio plugin host As DLL/Builds/VisualStudio2010/Plugin Host As DLL.sln”. Then just build the dll and run the DllCaller.

Any help getting Audio Plugin Host Demo to work as a dll would be greatly appreciated.

Thank you.


#9

Sorry, just realized that the links to the dll are absolute.

Here is a version with relative links: http://www.mediafire.com/?dodlkbabf351do3

Although you might need to redo the Framework and References under the Common Properties tab, to include the Plugin Host As DLL reference. Sorry for the inconvenience.


#10

Sorry, I’ve no time to look at your code.

Like I told you, DO NOT USE the application class. Your code is no longer an app, and that class is meaningless in this context. You’ll need to create your window in response to some kind of DLL function that your host calls.