我的应用程序中有以下代码行:
CString strAppName = AfxGetAppName();
有时它会用垃圾字符填充 strAppName
,我不明白为什么。
有人有什么想法吗?
TIA。
最佳答案
如果你改变 m_pszAppName
是可能的手动。
At the very beginning of application initialization,
AfxWinInit
callsCWinApp::SetCurrentHandles
, which caches the current value of them_pszAppName
pointer as follows:
pModuleState->m_lpszCurrentAppName = m_pszAppName;
That is, the module state struct holds a copy of the
m_pszAppName
pointer. If you changem_pszAppName
inInitInstance
as adviced in MSDN, you still have the old pointer value inpModuleState->m_lpszCurrentAppName
. TheAfxGetAppName()
function returnsAfxGetModuleState()->m_lpszCurrentAppName
.
您可以添加 data breakpoint在 m_lpszCurrentAppName 和 m_pszAppName
上.它在 <...>\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\appinit.cpp
中初始化文件。您将看到该变量发生了什么,以及谁在尝试更改它。
关于c++ - AfxGetAppName() 返回垃圾字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1268005/