X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=cbits%2FdirUtils.c;h=85aa0dcd4fc780f3497e1bb51f579c26e93a01bd;hb=567080c906535534628b1ab83a4a4425dcd4bb5e;hp=08ea54e550f3712c13fa3c1c6f3136d1aa153ff8;hpb=3bc707020c8d0f7a11b652c38d33f1d9c87d3ae7;p=haskell-directory.git diff --git a/cbits/dirUtils.c b/cbits/dirUtils.c index 08ea54e..85aa0dc 100644 --- a/cbits/dirUtils.c +++ b/cbits/dirUtils.c @@ -4,17 +4,18 @@ * Directory Runtime Support */ +/* needed only for solaris2_HOST_OS */ #include "ghcconfig.h" // The following is required on Solaris to force the POSIX versions of // the various _r functions instead of the Solaris versions. -#ifdef solaris2_TARGET_OS +#ifdef solaris2_HOST_OS #define _POSIX_PTHREAD_SEMANTICS #endif #include "HsBase.h" -#if defined(mingw32_TARGET_OS) || defined(__MINGW32__) || defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) #include static @@ -117,7 +118,7 @@ HsInt __hscore_renameFile( HsAddr src, HsAddr dest) { -#if defined(mingw32_TARGET_OS) || defined(__MINGW32__) || defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) static int forNT = -1; /* ToDo: propagate error codes back */ @@ -172,3 +173,47 @@ __hscore_renameFile( HsAddr src, #endif } +/* + * Function: __hscore_getFolderPath() + * + * Late-bound version of SHGetFolderPath(), coping with OS versions + * that have shell32's lacking that particular API. + * + */ +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) +typedef HRESULT (*HSCORE_GETAPPFOLDERFUNTY)(HWND,int,HANDLE,DWORD,char*); +int +__hscore_getFolderPath(HWND hwndOwner, + int nFolder, + HANDLE hToken, + DWORD dwFlags, + char* pszPath) +{ + static int loaded_dll = 0; + static HMODULE hMod = (HMODULE)NULL; + static HSCORE_GETAPPFOLDERFUNTY funcPtr = NULL; + /* The DLLs to try loading entry point from */ + char* dlls[] = { "shell32.dll", "shfolder.dll" }; + + if (loaded_dll < 0) { + return (-1); + } else if (loaded_dll == 0) { + int i; + for(i=0;i < sizeof(dlls); i++) { + hMod = LoadLibrary(dlls[i]); + if ( hMod != NULL && + (funcPtr = (HSCORE_GETAPPFOLDERFUNTY)GetProcAddress(hMod, "SHGetFolderPathA")) ) { + loaded_dll = 1; + break; + } + } + if (loaded_dll == 0) { + loaded_dll = (-1); + return (-1); + } + } + /* OK, if we got this far the function has been bound */ + return (int)funcPtr(hwndOwner,nFolder,hToken,dwFlags,pszPath); + /* ToDo: unload the DLL on shutdown? */ +} +#endif