Hendricks266

aSHGetSpecialFolderPathAtype

Nov 4th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #ifdef _WIN32
  2. typedef bool (WINAPI * aSHGetSpecialFolderPathAtype)(HWND, LPTSTR, int, BOOL);
  3. #endif
  4.  
  5. char *Bgethomedir(void)
  6. {
  7. #ifdef _WIN32
  8.     aSHGetSpecialFolderPathAtype aSHGetSpecialFolderPathA;
  9.     TCHAR appdata[MAX_PATH];
  10.     int32_t loaded = 0;
  11.     HMODULE hShell32 = GetModuleHandle("shell32.dll");
  12.  
  13.     if (hShell32 == NULL)
  14.     {
  15.         hShell32 = LoadLibrary("shell32.dll");
  16.         loaded = 1;
  17.     }
  18.  
  19.     if (hShell32 == NULL)
  20.         return NULL;
  21.  
  22.     aSHGetSpecialFolderPathA = (aSHGetSpecialFolderPathAtype)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
  23.     if (aSHGetSpecialFolderPathA != NULL)
  24.         if (SUCCEEDED(aSHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, FALSE)))
  25.         {
  26.             if (loaded)
  27.                 FreeLibrary(hShell32);
  28.             return Bstrdup(appdata);
  29.         }
  30.  
  31.     if (loaded)
  32.         FreeLibrary(hShell32);
  33.     return NULL;
  34. #elif
Advertisement
Add Comment
Please, Sign In to add comment