MFC 的 CString 的奇怪行为

发布于 2024-12-11 12:46:11 字数 2326 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂ガ小子 2024-12-18 12:46:11

而不是:

PCD_Dir = m_pRunPCD->m_PCD_Dir;

尝试:

PCD_Dir = (LPCTSTR) m_pRunPCD->m_PCD_Dir;

Instead of:

PCD_Dir = m_pRunPCD->m_PCD_Dir;

try:

PCD_Dir = (LPCTSTR) m_pRunPCD->m_PCD_Dir;
春风十里 2024-12-18 12:46:11

结果发现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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文