+const char* WXDLLEXPORT wxGetHomeDir(wxString *pstr)
+{
+ wxString& strDir = *pstr;
+
+ #ifdef __UNIX__
+ const char *szHome = getenv("HOME");
+ if ( szHome == NULL ) {
+ // we're homeless...
+ wxLogWarning(_("can't find user's HOME, using current directory."));
+ strDir = ".";
+ }
+ else
+ strDir = szHome;
+
+ // add a trailing slash if needed
+ if ( strDir.Last() != '/' )
+ strDir << '/';
+ #else // Windows
+ #ifdef __WIN32__
+ const char *szHome = getenv("HOMEDRIVE");
+ if ( szHome != NULL )
+ strDir << szHome;
+ szHome = getenv("HOMEPATH");
+ if ( szHome != NULL ) {
+ strDir << szHome;
+
+ // the idea is that under NT these variables have default values
+ // of "%systemdrive%:" and "\\". As we don't want to create our
+ // config files in the root directory of the system drive, we will
+ // create it in our program's dir. However, if the user took care
+ // to set HOMEPATH to something other than "\\", we suppose that he
+ // knows what he is doing and use the supplied value.
+ if ( strcmp(szHome, "\\") != 0 )
+ return strDir.c_str();
+ }
+
+ #else // Win16
+ // Win16 has no idea about home, so use the working directory instead
+ #endif // WIN16/32
+
+ // 260 was taken from windef.h
+ #ifndef MAX_PATH
+ #define MAX_PATH 260
+ #endif
+
+ wxString strPath;
+ ::GetModuleFileName(::GetModuleHandle(NULL),
+ strPath.GetWriteBuf(MAX_PATH), MAX_PATH);
+ strPath.UngetWriteBuf();
+
+ // extract the dir name
+ wxSplitPath(strPath, &strDir, NULL, NULL);
+
+ #endif // UNIX/Win
+
+ return strDir.c_str();
+}
+