1

I have a problem since yesterday morning that's driving me crazy by now.

Problem is that I want to create a dialogue to browse for a folder. For every OS older than Vista I use the SHBrowseForFolder() method which is working fine (also for Vista and newer).

For Vista and newer I would like to use the IFileDialog because of performance, nicer GUI etc.

When I try to compile the implemented code for IFileDialog, I get the following "No GUID" error:

Code:

IFileDialog *pfd = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));

Error:

error C2787: 'IFileDialog' : no GUID has been associated with this object

In a conversation with my boss he told me that we cannot set the compiler flag to vista and above due to compatibility for XP. The problem was solved here with setting the compiler flag: How do I use iFileDialog in a VC++ 2010 project converted from VC++ 6.0?

Is it possible to use IFileDialog anyway? Maybe the class can be linked dynamically?

Could you please give me advice on how to implement? Thanks in advance.

Community
  • 1
  • 1
danny187
  • 11
  • 2

2 Answers2

0

You need to use __uuidof(...) in order to create this object:

IFileDialog *pFileDialog;
hr = CoCreateInstance(__uuidof(FileDialog), NULL, CLSCTX_ALL, 
    __uuidof(pFileDialog), reinterpret_cast<void**>(&pFileDialog));
codencandy
  • 1,701
  • 1
  • 10
  • 20
0

If you want to compiler code that uses a higher SDK (post XP) you need to set the appropriate WINVER.

Doing this for the complete project wouldn't work, but doing it for this module that should run for later Windows OS than XP should work.

Setting WINVER to a higher version than XP for one of the modules should'nt be a problem as long as you don't use functions that are not available in XP.

xMRi
  • 14,982
  • 3
  • 26
  • 59