]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/utils.cpp
wxMimeTypesManager now supports creating associations as well as querying
[wxWidgets.git] / src / msw / utils.cpp
index 634668dd77a92fc84b5d10888a857578416b63e6..3d64ac17052c8951bea4e8d03502424588781eab 100644 (file)
@@ -457,6 +457,47 @@ bool wxDirExists(const wxString& dir)
 #endif // Win32/16
 }
 
+// ----------------------------------------------------------------------------
+// env vars
+// ----------------------------------------------------------------------------
+
+bool wxGetEnv(const wxString& var, wxString *value)
+{
+    // first get the size of the buffer
+    DWORD dwRet = ::GetEnvironmentVariable(var, NULL, 0);
+    if ( !dwRet )
+    {
+        // this means that there is no such variable
+        return FALSE;
+    }
+
+    if ( value )
+    {
+        (void)::GetEnvironmentVariable(var, value->GetWriteBuf(dwRet), dwRet);
+        value->UngetWriteBuf();
+    }
+
+    return TRUE;
+}
+
+bool wxSetEnv(const wxString& var, const wxChar *value)
+{
+    // some compilers have putenv() or _putenv() or _wputenv() but it's better
+    // to always use Win32 function directly instead of dealing with them
+#if defined(__WIN32__)
+    if ( !::SetEnvironmentVariable(var, value) )
+    {
+        wxLogLastError(_T("SetEnvironmentVariable"));
+
+        return FALSE;
+    }
+
+    return TRUE;
+#else // no way to set env vars
+    return FALSE;
+#endif
+}
+
 // ----------------------------------------------------------------------------
 // process management
 // ----------------------------------------------------------------------------