Search code examples
windowswinapivisual-c++comvisual-c++-2010

How do I use iFileDialog in a VC++ 2010 project converted from VC++ 6.0?


I am able to use a FileSaveDialog (Common Item Dialog) in a VC++ 2010 app like this:

IFileDialog *pFileDialog;
HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog));    

but when I put this code into my project that has been converted from VC++ 6.0 to VC++ 2010 I get the following error:

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

I also get a red squiggle under the IID_PPV_ARGS macro and the float-over error:

"operand of _uuidof must have a class or enum type for which _declspec(uuid('...')) has been specified"

I am NOT using the Common Language Runtime Support (/clr) in either project.

How do I associate a GUID with my object?


Solution

  • The problem was that I had set a compiler flag targeting the Win XP OS. That's why a feature introduced in Vista wasn't defined.

    I had _WIN32_WINNT = 0x0501 (WinXP). When I changed it to 0x0600 (Vista) the IFileDialog was defined.

    Mark, your suggestion about looking into the definition of IFileDialog lead me to the cause. It led me to the ShObjIdl.h file but the section where IFileDialog was defined was greyed out, leading me up to the #if (NTDDI_VERSION >= NTDDI_VISTA) conditional.

    Thanks!