I have C++ code where I'm trying to open a file select dialog with the Component Object Model's IFileDialog. The code works in Visual Studio but when I type the exact same code in VS Code, there are 2 errors:
IID_IFileOpenDialog' was not declared in this scope
and
invalid use of incomplete type 'IFileDialog' {aka 'struct IFileDialog'}
Here is the code which successfully loads the file select dialog in Visual Studio:
#include <iostream>
#include <objbase.h>
#include <ShObjIdl.h>
int main()
{
CoInitializeEx(nullptr, COINIT::COINIT_MULTITHREADED);
IFileDialog *fileDialog;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&fileDialog));
if (SUCCEEDED(hr)) {
fileDialog->AddRef();
fileDialog->Show(NULL);
}
else {
std::cout << "no" << std::endl;
}
CoUninitialize();
}
In VS Code, I am using the MinGW/gcc/g++ compiler (sorry, I don't know too much about compilers but I think all of those three make my code run), and in Visual Studio I'm not sure, next to the green play button it says Local Windows Debugger.
What causes this error to appear only in VS Code?