MFC 的 CString 的奇怪行为
我使用 MFC CString 得到了最奇怪的内存行为:
第 138 行:PCD_Dir = m_pRunPCD->m_PCD_Dir;
声明:
CString PCD_Dir; (file scope, defined as a global outside of CServer )
class CRunPCD {
public:
CString m_PCD_Dir;
}
调用堆栈:
Support.dll!CServer::Init(CCfcController * pv=0x007ebe78) Line 138 C++
Support.dll!CCfcController::OnInitialUpdate() Line 156 + 0xf bytes C++
Support.dll!CCfcApp::CCncApp() Line 140 C++
Support.dll!newInstance() Line 162 + 0x2c bytes C++
内存(来自监视窗口):
(wchar_t**)&(m_pRunPCD->m_PCD_Dir):
0x007ec270 wchar_t * *
m_pRunPCD->m_PCD_Dir.m_pszData:
0x007ee8a0 "C:\ProgramData\WAI\PC-DMIS\" wchar_t *
(wchar_t**)&PCD_Dir:
0x068f4698 class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > PCD_Dir wchar_t * *
PCD_Dir.m_pszData:
0x789cb8f8 "" wchar_t *
然后我进入作业,我的环境如下所示:< /strong>
代码:
// Assignment operators
CStringT& operator=(_In_ const CStringT& strSrc)
{
CThisSimpleString::operator=( strSrc );
return( *this );
}
调用堆栈:
mfc100ud.dll!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::operator=(const ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > & strSrc=<Bad Ptr>) Line 1218 C++
Support.dll!CServer::Init(CCfcController * pv=0x007ebe78) Line 141 C++
Support.dll!CCfcController::OnInitialUpdate() Line 156 + 0xf bytes C++
Support.dll!CCfcApp::CCncApp() Line 140 C++
Support.dll!newInstance() Line 162 + 0x2c bytes C++
内存:
&strSrc
0x007ec269 const ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > *
strSrc.m_pszData:
0xff000000 <Bad Ptr> wchar_t *
由于某种原因,该值没有正确传递......? 有趣的是,如果查看此框架:
CNCSupport.dll!CServer::Init(CCncController * pv=0x007ebe78) Line 141 C++
那么该值是正确的。 知道问题是什么吗?我完全被难住了。任何帮助将不胜感激!谢谢。
I am getting the strangest memory behavior using an MFC CString:
line 138: PCD_Dir = m_pRunPCD->m_PCD_Dir;
declarations:
CString PCD_Dir; (file scope, defined as a global outside of CServer )
class CRunPCD {
public:
CString m_PCD_Dir;
}
call stack:
Support.dll!CServer::Init(CCfcController * pv=0x007ebe78) Line 138 C++
Support.dll!CCfcController::OnInitialUpdate() Line 156 + 0xf bytes C++
Support.dll!CCfcApp::CCncApp() Line 140 C++
Support.dll!newInstance() Line 162 + 0x2c bytes C++
memory (from watch window):
(wchar_t**)&(m_pRunPCD->m_PCD_Dir):
0x007ec270 wchar_t * *
m_pRunPCD->m_PCD_Dir.m_pszData:
0x007ee8a0 "C:\ProgramData\WAI\PC-DMIS\" wchar_t *
(wchar_t**)&PCD_Dir:
0x068f4698 class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > PCD_Dir wchar_t * *
PCD_Dir.m_pszData:
0x789cb8f8 "" wchar_t *
I then step into the assignment and my environment looks like this:
code:
// Assignment operators
CStringT& operator=(_In_ const CStringT& strSrc)
{
CThisSimpleString::operator=( strSrc );
return( *this );
}
call stack:
mfc100ud.dll!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::operator=(const ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > & strSrc=<Bad Ptr>) Line 1218 C++
Support.dll!CServer::Init(CCfcController * pv=0x007ebe78) Line 141 C++
Support.dll!CCfcController::OnInitialUpdate() Line 156 + 0xf bytes C++
Support.dll!CCfcApp::CCncApp() Line 140 C++
Support.dll!newInstance() Line 162 + 0x2c bytes C++
memory:
&strSrc
0x007ec269 const ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > *
strSrc.m_pszData:
0xff000000 <Bad Ptr> wchar_t *
so for some reason the value is not getting passed correctly...?
interestingly, if look in this frame:
CNCSupport.dll!CServer::Init(CCncController * pv=0x007ebe78) Line 141 C++
then the value is correct.
any idea what the problem is?! i am completely stumped. any help would be greatly appreciated! thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是:
尝试:
Instead of:
try:
结果发现strSrc和m_pRunPCD->m_PCD_Dir的地址偏移了1,这就是缓冲区指针无效的原因。事实证明,我错误地启用了头文件中的打包来解决导致此问题的另一个问题。
Turns out that the address of strSrc and m_pRunPCD->m_PCD_Dir were offset by 1, which was the reason the buffer pointer was invalid. turns out I had incorrectly enabled packing in a header file to resolve another issue which led to this issue.