I want to open windows explorer to select file using juce::FileChooser in console.

#include <JuceHeader.h>
using namespace std;

int main (int argc, char* argv[])
	cout << "juce test";
	juce::FileChooser chooser("Select a Wave file",
	//juce::MessageManagerLock mmLock (); //[1]
	//juce::MessageManagerLock mmLock (juce::Thread::getCurrentThread()); //[2]
	if (chooser.browseForFileToOpen()){}
	return 0;

I wrote the above code to open windows file explorer in console,
The code above gives the error JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED.

So I looked up the MessageManagerLock documentation, and added the code [1]. Then I get the jassertfalse error.
Next, I replaced code[1] with code[2] knowing that the thread address was missing, but I still get the error.
From the related documentation, I know that I can’t get the address from the main thread, so I’m browsing the documentation to create a new thread.
However, it is questionable whether this method is a fundamental solution to the problem.

What should I do to solve this problem?
Is it impossible to open windows explorer from console in the first place?

p.s. Since English is not my native language, I am asking a question by translating it with Google Translator.

In a console application you will need to initialise the JUCE event loop manually at the top of main(). You can either do this by calling initialiseJuce_GUI() at the top and then shutdownJuce_GUI() when you are finished, or by creating an instance of ScopedJuceInitialiser_GUI to do this in an RAII manner.

1 Like

Oh, thank you so much. I solved it! :+1: