initialiseJuce_GUI proper calling


#1

When I use initialiseJuce_GUI(), the Juce GUI is not launching. My apologies in advance for the cross-post, folks, but I really need some help - I’m not sure where to put initialiseJuce_GUI(), or how it needs to be used. This is for an open source security tool that is freely available. The current version is working, but doesn’t compile on Fedora with a juce compile error. When I upgraded juce_amalgamated to the latest, I have some compile errors and found out from Jules that I need to use initialiseJuce_GUI. It compiles on fedora now, but the GUI doesn’t launch. Helping me with this will make Juce even more popular, being used in an open source security tool.

This is the function within a cpp file that is calling initialiseJuce_GUI(). The entire cpp file is below. What am I missing?:

void *startUCSniffJUCEGUI(void *){
	
	int retval = startJUCE();
	return NULL;
}
int startJUCE ()
{
        initialiseJuce_GUI();

        //char *argv[] = {"ucsniff.exe"};
        //return JUCE_NAMESPACE::JUCEApplication::main (1, argv, new JUCEUCSniffApplication());

        //const char *argv[] = {"ucsniff.exe"};
        //return JUCE_NAMESPACE::JUCEApplication::main (1, argv);
}

How does the call to initialiseJuce_GUI() know the name of the JUCEApplication, because the call to main used to work before, and it returned the JUCEApplication class name??

This is the relevant C program code and main within that code that is calling the function in the Juce CPP via a thread:

                int rc = pthread_create(&threads[0],NULL,startUCSniffJUCEGUI,NULL);
                if(rc){
                        printf("Error Creating thread for JUCE GUI : %d\n",rc);
                        exit(1);
                }

cpp code for JuceUCSniff.cpp:

#include "includes_juce.h"
#include "MainComponent.h"

extern int guiShutdown;

extern "C" {
	void *startUCSniffJUCEGUI(void *);
};

extern "C" {
	int startJUCE();
}

class UCSniffWindow  : public DocumentWindow
{
public:
    UCSniffWindow()
        : DocumentWindow (T("UCSniff GUI"),
                          //Colours::lightgrey,
                          Colours::white,
                          DocumentWindow::allButtons,
                          true)
    {
        MainComponent* const contentComponent = new MainComponent();
        setContentComponent (contentComponent, true, true);
        centreWithSize (getWidth(), getHeight());
        setVisible (true);
    }

    ~UCSniffWindow()
    {

    }

    void closeButtonPressed()
    {
        // When the user presses the close button, we'll tell the app to quit. This
        // window will be deleted by our UCSniffApplication::shutdown() method
        //
        JUCEApplication::quit();
    }
};

//==============================================================================
/** This is the application object that is started up when Juce starts. It handles
    the initialisation and shutdown of the whole application.
*/
class JUCEUCSniffApplication : public JUCEApplication
{
    /* Important! NEVER embed objects directly inside your JUCEApplication class! Use
       ONLY pointers to objects, which you should create during the initialise() method
       (NOT in the constructor!) and delete in the shutdown() method (NOT in the
       destructor!)

       This is because the application object gets created before Juce has been properly
       initialised, so any embedded objects would also get constructed too soon.
   */
    UCSniffWindow* ucsniffWindow;

public:
    //==============================================================================
    JUCEUCSniffApplication()
        : ucsniffWindow (0)
    {
        // NEVER do anything in here that could involve any Juce function being called
        // - leave all your startup tasks until the initialise() method.
    }

    ~JUCEUCSniffApplication()
    {
        // Your shutdown() method should already have done all the things necessary to
        // clean up this app object, so you should never need to put anything in
        // the destructor.

        // Making any Juce calls in here could be very dangerous...
    }

    //==============================================================================
    void initialise (const String& commandLine)
    {
		
        // just create the main window...
        ucsniffWindow = new UCSniffWindow();

        /*  ..and now return, which will fall into to the main event
            dispatch loop, and this will run until something calls
            JUCEAppliction::quit().

            In this case, JUCEAppliction::quit() will be called by the
            hello world window being clicked.
        */
    }

    void shutdown()
    {
        // clear up..

		if (ucsniffWindow != 0){
            delete ucsniffWindow;
			guiShutdown = 1;
		}
    }

    //==============================================================================
    const String getApplicationName()
    {
        return T("VIPER Lab UCSniff");
    }

    const String getApplicationVersion()
    {
        return T("1.0");
    }

    bool moreThanOneInstanceAllowed()
    {
        return true;
    }

    void anotherInstanceStarted (const String& commandLine)
    {
    }
};


//==============================================================================
// This macro creates the application's main() function..
//START_JUCE_APPLICATION (JUCEUCSniffApplication)

void *startUCSniffJUCEGUI(void *){
	
	int retval = startJUCE();
	return NULL;
}

int startJUCE () 
{ 
	initialiseJuce_GUI();

	//char *argv[] = {"ucsniff.exe"};
	//return JUCE_NAMESPACE::JUCEApplication::main (1, argv, new JUCEUCSniffApplication());
	
	//const char *argv[] = {"ucsniff.exe"};
	//return JUCE_NAMESPACE::JUCEApplication::main (1, argv);
}

#2

I don’t understand what you’re trying to do.

If you want a GUI app, you need to just start it in the normal way. Why are you trying to write your own launch code?


#3

Because the C application was already written years ago as a console application, and then we overlayed a Juce GUI on top of it. So the Juce GUI is launched as:
ucsniff -G

and this should init the thread that launches the Juce GUI. It did work before with the older Juce amalgamated, with the C thread launching the function that returns the Juce application, but now with the new Juce amalgamated code, I now have to get it working with the proper calling of initialiseJuce_GUI().

The issue I am dealing with is that we were using this main call (below) in the older juce_amalgated to launch the GUI, but now it has gone away in the newer juce_amalgamated. Would love to figure out how to use the new initialiseJuce_GUI to do the same thing that this was doing:

int JUCEApplication::main (int argc, char* argv[], JUCEApplication* const newApp)

#4

Just rename your old main() method to something else and call it from your JUCEApplication’s initialise method. Trying to bodge juce’s startup sequence to fit into a console app sounds like the wrong approach to me.