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

2

7

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?

Tableware answered 17/3, 2011 at 23:19 Comment(0)
T
5

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!

Tableware answered 18/3, 2011 at 20:31 Comment(0)
H
1

My VC++ 6.0 doesn't define IFileDialog, not in the base package and not in the Windows SDK. Did you back port it from somewhere?

I would look at the definition of IFileDialog in VC++ 10. I'm guessing it's defined with the benefit of some macro, and that macro includes or excludes the _declspec(uuid('...')) depending on some compile-time constant which is set wrong.

Edit: In VC++ 10 IFileDialog is defined with the help of the MIDL_INTERFACE macro, in ShObjIdl.h. The MIDL_INTERFACE macro is defined in 3 different files, so it's hard to tell which definition you're picking up; they're all different. However I don't see any way in which the definition wouldn't be associated with a GUID.

Is it possible you're doing a forward definition of IFileDialog on your own that does not include the GUID?

Hyperspace answered 18/3, 2011 at 1:1 Comment(2)
I wasn't using IFileDialog in VC++ 6.0. I'm adding it to the project after it has been converted to VC++ 2010.Tableware
IFileDialog is defined in ShObjIdl.h like this: 'code' #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("42f85136-db7e-439c-85f1-e4075d135fc8") IFileDialog : public IModalWindow {...... This looks like IFileDialog is associated with a GUID via the MIDL_INTERFACE macro.Tableware

© 2022 - 2024 — McMap. All rights reserved.