AfxGetAppName()返回垃圾字符 [英] AfxGetAppName() returns garbage characters

查看:718
本文介绍了AfxGetAppName()返回垃圾字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有以下代码:




CString strAppName = AfxGetAppName();



有时它会用 strAppName 填充垃圾字符,我不知道为什么。 / p>

任何人都有任何想法?



TIA。

解决方案

如果您手动更改 m_pszAppName ,这是可能的。


在应用程序初始化的开始, AfxWinInit 调用 CWinApp :: SetCurrentHandles m_pszAppName 指针的值如下:

pModuleState-> m_lpszCurrentAppName = m_pszAppName;



也就是说,模块状态结构保存着 m_pszAppName 指针的副本。如果你改变在MSDN中提供的 m_pszAppName in InitInstance ,你仍然有旧指针值 pModuleState-> m_lpszCurrentAppName AfxGetAppName()函数返回 AfxGetModuleState() - > m_lpszCurrentAppName


< blockquote>

您可以添加数据断点 on m_lpszCurrentAppName和 m_pszAppName 。它在< ...> \ Microsoft Visual Studio 9.0 \VC\atlmfc\src\mfc\appinit.cpp 文件中初始化。你会看到这个变量发生了什么,以及谁试图改变它。


I have the following line of code in my application:

CString strAppName = AfxGetAppName();

Sometimes it fills strAppName up with garbage characters, and I can't figure out why.

Anyone have any ideas?

TIA.

解决方案

That is possible if you change m_pszAppName manually.

At the very beginning of application initialization, AfxWinInit calls CWinApp::SetCurrentHandles, which caches the current value of the m_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 change m_pszAppName in InitInstance as adviced in MSDN, you still have the old pointer value in pModuleState->m_lpszCurrentAppName. The AfxGetAppName() function returns AfxGetModuleState()->m_lpszCurrentAppName.

You could add data breakpoint on m_lpszCurrentAppName and on m_pszAppName. It is initialized in <...>\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\appinit.cpp file. You'll see what is going on with that variable and who's trying to change it.

这篇关于AfxGetAppName()返回垃圾字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆