Skip to content

Instantly share code, notes, and snippets.

@hadley
Created July 23, 2012 17:11
Show Gist options
  • Save hadley/3164779 to your computer and use it in GitHub Desktop.
Save hadley/3164779 to your computer and use it in GitHub Desktop.
#include <R.h>
#include <Rdefines.h>
#ifdef WIN32
#include <shlobj.h>
// SHGetFolderPath documentation:
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181.aspx
SEXP get_folder_path() {
// I think this should be wchar_t, but that won't compile for me
TCHAR startupFolder[MAX_PATH];
HRESULT hr = SHGetFolderPath(0, CSIDL_STARTUP, 0, 0, startupFolder);
if (SUCCEEDED(hr)) {
// Get short path
TCHAR shortPath[MAX_PATH];
GetShortPathName(startupFolder, shortPath, MAX_PATH);
return mkString(shortPath);
}
else {
// Return NULL if failed
return R_NilValue;
}
}
#else
SEXP get_folder_path() {
return R_NilValue;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment