JuceApplication as Windows service - MessageManager Problems


#1

Hi,
I’m trying to set up a JuceApplication as a Windows service. It all works so far as I’m only using juce functions without the MessageManager and therefore without Threads or anything that depends on the MessageLoop. But exactly this is what I need.
A Windows service has it’s own main function that is instantiating the services main function (for clearence let’s call this “serviceStart” which in fact is a normal function and can’t be a real juceApplication). From this serviceStart I need to run my JuceApp, which has some threads on it’s own and depends on the MessageManager.
Since a windows service doesn’t have any GUI, the kind of thing I need is described best as a juce command line app, with a messageloop, that can be started from within another applications main function and doesn’t have a real windows main function on its own.

What I tried so far is to wait untill the main function of the windows service has called the serviceStart in an own thread and then do something like this:

void ServiceWrapper::serviceStart(int argc, char **argv)
{
	//...
	//initialise the service and the windows service control handler
	//...

	controlHandler (SERVICE_RUNNING);
	
	initialiseJuce_GUI(); //can't use initialiseJuce_NonGUI() because of the missing MessageManager stuff
	
	MessageManager::getInstance()->setCurrentMessageThread(Thread::getCurrentThreadId());
	
	/*	Here is my problem: the createMyJuceApplicationClass is a class that does the work of my juce Application,
		it creates some threads handles messages and so on.
		If I create this class before MessageManager::getInstance()->runDispatchLoop(), things don't work because
		the dispatch loop isn't running. 
		If I call createMyJuceApplicationClass() after MessageManager::getInstance()->runDispatchLoop(), it will
		never be called untill the MessageManager loop stops.
	*/

	createMyJuceApplicationClass();
	
	MessageManager::getInstance()->runDispatchLoop(); //run this untill the service gets a signal to stop

	deleteMyJuceApplicationClass();

	controlHandler (SERVICE_STOPPED); 

	shutdownJuce_GUI();
}

So maybe this is a silly way to do that, but I have no idea how to setup this correctly.
Any hints to point me in the right direction appreciated.

Thanks