Index: /trunk/src/VBox/Additions/common/crOpenGL/load.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/load.c	(revision 51672)
+++ /trunk/src/VBox/Additions/common/crOpenGL/load.c	(revision 51673)
@@ -1134,4 +1134,5 @@
 #ifdef VDBG_VEHANDLER
 # include <dbghelp.h>
+# include <cr_string.h>
 static PVOID g_VBoxVehHandler = NULL;
 static DWORD g_VBoxVehEnable = 0;
@@ -1144,11 +1145,5 @@
 #define VBOXVEH_F_EXIT  0x00000004
 
-static DWORD g_VBoxVehFlags = 0
-#ifdef DEBUG_misha
-                            | VBOXVEH_F_BREAK
-#else
-                            | VBOXVEH_F_DUMP
-#endif
-        ;
+static DWORD g_VBoxVehFlags = 0;
 
 typedef BOOL WINAPI FNVBOXDBG_MINIDUMPWRITEDUMP(HANDLE hProcess,
@@ -1163,5 +1158,5 @@
 static HMODULE g_hVBoxMdDbgHelp = NULL;
 static PFNVBOXDBG_MINIDUMPWRITEDUMP g_pfnVBoxMdMiniDumpWriteDump = NULL;
-static uint32_t g_cVBoxMdFilePrefixLen = 0;
+static size_t g_cVBoxMdFilePrefixLen = 0;
 static WCHAR g_aszwVBoxMdFilePrefix[MAX_PATH];
 static WCHAR g_aszwVBoxMdDumpCount = 0;
@@ -1191,5 +1186,6 @@
 
 
-#define VBOXMD_DUMP_DIR_PREFIX_DEFAULT L"C:\\dumps\\vboxdmp"
+#define VBOXMD_DUMP_DIR_DEFAULT "C:\\dumps"
+#define VBOXMD_DUMP_NAME_PREFIX_W L"VBoxDmp_"
 
 static HMODULE loadSystemDll(const char *pszName)
@@ -1229,17 +1225,4 @@
         if (!g_pfnVBoxMdMiniDumpWriteDump)
             return GetLastError();
-    }
-
-    /* @todo: this is a tmp stuff until we get that info from the settings properly */
-    if (!g_cVBoxMdFilePrefixLen)
-    {
-        g_cVBoxMdFilePrefixLen = sizeof (VBOXMD_DUMP_DIR_PREFIX_DEFAULT)/sizeof (g_aszwVBoxMdFilePrefix[0]) - 1 /* <- don't include nul terminator */;
-        memcpy(g_aszwVBoxMdFilePrefix, VBOXMD_DUMP_DIR_PREFIX_DEFAULT, sizeof (VBOXMD_DUMP_DIR_PREFIX_DEFAULT));
-    }
-
-
-    if (RT_ELEMENTS(aszwMdFileName) <= g_cVBoxMdFilePrefixLen)
-    {
-        return ERROR_INVALID_STATE;
     }
 
@@ -1341,4 +1324,5 @@
     {
         CRNetServer ns;
+        const char * env;
 
 #ifdef CHROMIUM_THREADSAFE
@@ -1349,10 +1333,95 @@
 
 #ifdef VDBG_VEHANDLER
-        g_VBoxVehEnable = !!crGetenv("CR_DBG_VEH_ENABLE");
+        env = crGetenv("CR_DBG_VEH_ENABLE");
+        g_VBoxVehEnable = crStrParseI32(env,
 # ifdef DEBUG_misha
-        g_VBoxVehEnable = 1;
+                1
+# else
+                0
 # endif
+                );
+
         if (g_VBoxVehEnable)
+        {
+            char procName[1024];
+            size_t cProcName;
+            size_t cChars;
+
+            env = crGetenv("CR_DBG_VEH_FLAGS");
+            g_VBoxVehFlags = crStrParseI32(env,
+                    0
+# ifdef DEBUG_misha
+                    | VBOXVEH_F_BREAK
+# else
+                    | VBOXVEH_F_DUMP
+# endif
+                    );
+
+            env = crGetenv("CR_DBG_VEH_DUMP_DIR");
+            if (!env)
+                env = VBOXMD_DUMP_DIR_DEFAULT;
+
+            g_cVBoxMdFilePrefixLen = strlen(env);
+
+            if (RT_ELEMENTS(g_aszwVBoxMdFilePrefix) <= g_cVBoxMdFilePrefixLen + 26 + (sizeof (VBOXMD_DUMP_NAME_PREFIX_W) - sizeof (WCHAR)) / sizeof (WCHAR))
+            {
+                g_cVBoxMdFilePrefixLen = 0;
+                env = "";
+            }
+
+            mbstowcs_s(&cChars, g_aszwVBoxMdFilePrefix, g_cVBoxMdFilePrefixLen + 1, env, _TRUNCATE);
+
+            Assert(cChars == g_cVBoxMdFilePrefixLen + 1);
+
+            g_cVBoxMdFilePrefixLen = cChars - 1;
+
+            if (g_cVBoxMdFilePrefixLen && g_aszwVBoxMdFilePrefix[g_cVBoxMdFilePrefixLen - 1] != L'\\')
+                g_aszwVBoxMdFilePrefix[g_cVBoxMdFilePrefixLen++] = L'\\';
+
+            memcpy(g_aszwVBoxMdFilePrefix + g_cVBoxMdFilePrefixLen, VBOXMD_DUMP_NAME_PREFIX_W, sizeof (VBOXMD_DUMP_NAME_PREFIX_W) - sizeof (WCHAR));
+            g_cVBoxMdFilePrefixLen += (sizeof (VBOXMD_DUMP_NAME_PREFIX_W) - sizeof (WCHAR)) / sizeof (WCHAR);
+
+            crGetProcName(procName, RT_ELEMENTS(procName));
+            cProcName = strlen(procName);
+
+            if (RT_ELEMENTS(g_aszwVBoxMdFilePrefix) > g_cVBoxMdFilePrefixLen + cProcName + 1 + 26)
+            {
+                mbstowcs_s(&cChars, g_aszwVBoxMdFilePrefix + g_cVBoxMdFilePrefixLen, cProcName + 1, procName, _TRUNCATE);
+                Assert(cChars == cProcName + 1);
+                g_cVBoxMdFilePrefixLen += cChars - 1;
+                g_aszwVBoxMdFilePrefix[g_cVBoxMdFilePrefixLen++] = L'_';
+            }
+
+            /* sanity */
+            g_aszwVBoxMdFilePrefix[g_cVBoxMdFilePrefixLen] = L'\0';
+
+            env = crGetenv("CR_DBG_VEH_DUMP_TYPE");
+
+            g_enmVBoxMdDumpType = crStrParseI32(env,
+                    MiniDumpNormal
+                    | MiniDumpWithDataSegs
+                    | MiniDumpWithFullMemory
+                    | MiniDumpWithHandleData
+            ////        | MiniDumpFilterMemory
+            ////        | MiniDumpScanMemory
+            //        | MiniDumpWithUnloadedModules
+            ////        | MiniDumpWithIndirectlyReferencedMemory
+            ////        | MiniDumpFilterModulePaths
+            //        | MiniDumpWithProcessThreadData
+            //        | MiniDumpWithPrivateReadWriteMemory
+            ////        | MiniDumpWithoutOptionalData
+            //        | MiniDumpWithFullMemoryInfo
+            //        | MiniDumpWithThreadInfo
+            //        | MiniDumpWithCodeSegs
+            //        | MiniDumpWithFullAuxiliaryState
+            //        | MiniDumpWithPrivateWriteCopyMemory
+            //        | MiniDumpIgnoreInaccessibleMemory
+            //        | MiniDumpWithTokenInformation
+            ////        | MiniDumpWithModuleHeaders
+            ////        | MiniDumpFilterTriage
+                    );
+
             vboxVDbgVEHandlerRegister();
+        }
 #endif
 
