0

In an desktop-bridge app, I want to find the LocalAppData (or LocalCache) folder of that specific package. I can get the LocalCache folder path with ApplicationData class:

using Windows.Storage;
string appData = ApplicationData.Current.LocalCacheFolder.Path;

Alternatively, if I use SHGetKnownFolderPath function I can also get that same path:

wchar_t* appData;
SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_FORCE_APP_DATA_REDIRECTION, NULL, &appData);

So my question: Is it appropriate to use SHGetKnownFolderPath() instead of ApplicationData class? Both give same path in UWP environment. Is there any drawback/cons to use the first one?

Community
  • 1
  • 1
Biswapriyo
  • 3,491
  • 3
  • 22
  • 42
  • I won't be surprised if first approach actually involved a nested call to `SHGetKnownFolderPath` with some extra overhead but `SHGetKnownFolderPath` is not available for UWP environment at all. Not sure whether such a restriction apply to the desktop-bridge app. – user7860670 May 06 '18 at 20:32
  • One drawback of calling `SHGetKnownFolderPath` is, that you are responsible for memory management. And since you asked for *any* drawbacks, VTT is correct in pointing out, that this API call isn't available to UWP applications. Even if this code is in a desktop application currently, it just makes it harder to move it into a Windows Runtime Component. – IInspectable May 06 '18 at 20:57

1 Answers1

0

You could call any methods before you convert your desktop app to UWP app. Once you converted it successfully, after that, if you want to extend it, for example: Extend your desktop application with modern UWP components, then, you would have to use UWP APIs.

Xie Steven
  • 8,544
  • 1
  • 9
  • 23