Remove non-directory stuff (of base), and rename package to "directory"
[haskell-directory.git] / cbits / directory.c
1 /* 
2  * (c) The University of Glasgow 2002
3  *
4  */
5
6 #define INLINE
7 #include "HsDirectory.h"
8
9 /*
10  * Function: __hscore_getFolderPath()
11  *
12  * Late-bound version of SHGetFolderPath(), coping with OS versions
13  * that have shell32's lacking that particular API.
14  *
15  */
16 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
17 typedef HRESULT (*HSCORE_GETAPPFOLDERFUNTY)(HWND,int,HANDLE,DWORD,char*);
18 int
19 __hscore_getFolderPath(HWND hwndOwner,
20                        int nFolder,
21                        HANDLE hToken,
22                        DWORD dwFlags,
23                        char*  pszPath)
24 {
25     static int loaded_dll = 0;
26     static HMODULE hMod = (HMODULE)NULL;
27     static HSCORE_GETAPPFOLDERFUNTY funcPtr = NULL;
28     /* The DLLs to try loading entry point from */
29     char* dlls[] = { "shell32.dll", "shfolder.dll" };
30     
31     if (loaded_dll < 0) {
32         return (-1);
33     } else if (loaded_dll == 0) {
34         int i;
35         for(i=0;i < sizeof(dlls); i++) {
36             hMod = LoadLibrary(dlls[i]);
37             if ( hMod != NULL &&
38                  (funcPtr = (HSCORE_GETAPPFOLDERFUNTY)GetProcAddress(hMod, "SHGetFolderPathA")) ) {
39                 loaded_dll = 1;
40                 break;
41             }
42         }
43         if (loaded_dll == 0) {
44             loaded_dll = (-1);
45             return (-1);
46         }
47     }
48     /* OK, if we got this far the function has been bound */
49     return (int)funcPtr(hwndOwner,nFolder,hToken,dwFlags,pszPath);
50     /* ToDo: unload the DLL on shutdown? */
51 }
52 #endif
53