OS: Windows 10
JUCE: 7.0.4 (although looks like JUCE 8 still has the same code)
Projucer project type: Console Application
Expected Behavior:
Calling File::revealToUser() opens the file in Explorer.
Actual Behavior:
Calling File::revealToUser() does nothing and no errors or asserts are triggered or returned.
I’ve created a cross-platform console application using the Projucer. When attempting to reveal a log file to the user, File::revealToUser() fails on Windows.
When modifying the code to get the HRESULT from shOpenFolderAndSelectItems(), I get the following result:
if (ITEMIDLIST* const itemIDList = ilCreateFromPathW (fullPath.toWideCharPointer()))
{
HRESULT result = shOpenFolderAndSelectItems (itemIDList, 0, nullptr, 0);
ilFree (itemIDList);
}
HRESULT:
0x800401f0: CoInitialize has not been called.
I’m not sure if CoInitialize() or CoInitializeEx() is the correct call to use here, but SHOpenFolderAndSelectItems() indicates that calling it before calling CoInitialize() or CoInitializeEx() will result in this error.
My take is that when a JUCE GUI application initializes, it probably also calls one of these two functions so successive calls to SHOpenFolderAndSelectItems() succeed. But in this case since it’s a console application, this has not happened so revealToUser() fails silently.
If it’s possible to check for proper initialization in the Windows implementation of File::revealToUser() and either call it as needed, or at least assert so that as the developer I know it’s on me to call it myself in a console app, that would be way better than a silent failure with no errors on a basic file system operation that I would expect to work.
Update:
Calling CoInitialize(nullptr) fixed it for me given the single-threaded nature of my app.
