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

I can use FileSaveDialog (Common Item Dialog) in a VC ++ 2010 application as follows:

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

but when I put this code in my project, which was converted from VC ++ 6.0 to VC ++ 2010, I get the following error:

"C2787: 'IFileDialog': no โ€‹โ€‹GUID was associated with this object

I also get a red curve under the macro IID_PPV_ARGS and a floating point error:

"the _uuidof operand must be of the class or enumeration type for which _declspec (uuid ('...')) is specified"

I DO NOT use Common Language Runtime Support (/ clr) support in any project.

How to associate a GUID with my object?

+6
windows visual-c ++ winapi visual-c ++ - 2010 com
source share
2 answers

The problem was that I set the compiler flag oriented to Win XP OS. This is why the feature introduced in Vista was not defined.

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

Note that your search suggestion in the IFileDialog definition will lead me to the point. This led me to the ShObjIdl.h file, but the section in which IFileDialog was defined was grayed out, which led me to the #if (NTDDI_VERSION >= NTDDI_VISTA) conditional.

Thanks!

+5
source share

My VC ++ 6.0 does not define IFileDialog, and not in the base package, and not in the Windows SDK. Did you return it from somewhere?

I would look at the definition of IFileDialog in VC ++ 10. I assume that it is defined with benefit for some macro, and this macro includes or excludes _declspec(uuid('...')) depending on some compile-time constant, which not installed correctly.

Edit: In VC ++ 10, IFileDialog is defined using the MIDL_INTERFACE macro in ShObjIdl.h. The MIDL_INTERFACE macro is defined in three different files, so it is difficult to determine which definition you are building; they are all different. However, I see no way that the definition would not be associated with a GUID.

Is it possible that you are performing a direct IFileDialog definition yourself, not including a GUID?

+1
source share

All Articles