cwinapiwindows-7windows-vistaknown-folders

Calling SHGetKnownFolderPath from C code


I'm trying to call the Vista function SHGetKnownFolderPath() from C using Visual Studio 2008. The code works fine as C++ but refuses to compile as C code with this output:

xyz\indexwiki.cpp(316) : error C2440: 'function' : cannot convert from 'const GUID' to 'const KNOWNFOLDERID *const ' xyz\indexwiki.cpp(316) : warning C4024: 'SHGetKnownFolderPath' : different types for formal and actual parameter 1

The code is pretty much:

PWSTR path;

HRESULT hr = SHGetKnownFolderPath(
  FOLDERID_Profile,
  0,
  NULL,
  &path
);

I'd prefer to keep it as C and keep the project as a single source file if I can. Is this a known problem with newer Windows APIs? I couldn't find much via Google. Am I missing something? Or is there perhaps a simple workaround involving casting or preprocessor defines?


Solution

  • How about the following?

    HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Profile, 0, NULL, &path);