【发布时间】:2011-09-22 21:23:06
【问题描述】:
我有一个 win32 c++ 应用程序,我获取了所有环境变量并将它们存储在地图中。
当我在我的应用程序中调用 Win32 函数 FreeEnvironmentStrings() 时,我在 MSVC++ 中得到一个奇怪的 Windows 断点。首先我不知道这意味着什么以及为什么会发生?
我该如何解决我的问题以及出了什么问题?
这是我在主函数中调用的函数和导致断点的函数:
std::map <tstring, tstring> GetEnvironmentVariablesEx()
{
// Post: Get all windows environment variables & store in a
// map(key=env.. variable name, value=env variable value)
std::map <tstring, tstring> envVariables;
TCHAR* environVar = GetEnvironmentStrings();
TCHAR* pos = _tcschr( environVar, _T('\0') );
// Skip over the "=::=::\0" of the environVar string
if ( pos != NULL ) { environVar = ++pos; pos = _tcschr( environVar, _T('\0') ); }
else return envVariables;
// I removed the following code because its long & distracting: the error still occurs without the code
// Code: ...use cstring functions to extract environ variables & values & store in map
FreeEnvironmentStrings( environVar ); // Breakpoint triggered here: "Windows has triggered a breakpoint in the application. This may be due to a corruption of the heap, which indicates a bug in myApp.exe or any of the DLLs it has loaded."
return envVariables;
}
【问题讨论】:
标签: c++ winapi environment-variables