简体   繁体   English

WTL和CContainedWindow导致访问冲突

[英]WTL and CContainedWindow causing access violation

I am trying to subclass a progress control in a dialog box using this code: 我试图使用以下代码在对话框中将进度控件子类化:

ATL::CContainedWindowT<WTL::CProgressBarCtrl> progress;
// ...
progress.SubclassWindow(GetDlgItem(IDC_PROGRESS));

All good there. 那里一切都很好。 Now if I try to do this: 现在,如果我尝试这样做:

progress.SetRange(0, 100);

I get access violation exception on SendMessage in a trivial WTL's SetRange() implementation. 在普通WTL的SetRange()实现中, SendMessage上出现访问冲突异常。 I have been searching up and down and all I could find was this could be some "thunking" issue as mentioned in Applications Using Older ATL Components May Experience Conflicts With DEP which should not really apply to me because I am using the latest ATL and WTL (Visual Studio 2010 and WTL 8.1 ). 我一直在搜寻,发现的可能是“ 使用旧版ATL组件的应用程序中可能遇到的一些问题”,因为我使用的是最新的ATL和WTL,它与DEP可能不会真正发生冲突。 (Visual Studio 2010和WTL 8.1 )。 I get the same issue even if I use WTL 8.0. 即使使用WTL 8.0,我也会遇到相同的问题。

Subclassing was done OK as HWND is valid. HWND有效,因此可以完成子分类。 Any ideas? 有任何想法吗?

WTL::CProgressBarCtrl m_Progress; WTL :: CProgressBarCtrl m_Progress; <~ use that to attach the progress bar, not CContainedWindow. <〜使用它来附加进度条,而不是CContainedWindow。

If you subclass a window, then you are expected to implement a message map for this subclassed control. 如果将窗口子类化,则应为此子类控件实现消息映射。 This includes connecting your member variable to message map in constructor, adding ALT_MSG_MAP to the class message map. 这包括将成员变量连接到构造ALT_MSG_MAP中的消息映射,将ALT_MSG_MAP添加到类消息映射。 Are you doing this? 你在做这个吗? I suppose you do not. 我想你不会。

Do you need this in first place? 首先需要这个吗? To only send messages you don't need subclassing, you only need to attach real HWND to the CProgressBarCtrl instance: 要仅发送不需要子类化的消息,只需将实际HWND附加到CProgressBarCtrl实例:

WTL::CProgressBarCtrl m_ProgressBar;
// ...
m_ProgressBar = GetDlgItem(IDC_PROGRESS);
m_ProgressBar.SetRange(...

Subclassing was done OK as HWND is valid HWND有效,因此可以完成子分类

No, it was not OK. 不,那不行。 You hooked the window but you did not supply your WindowProc. 您钩了窗口,但没有提供WindowProc。 Hence, the issue. 因此,问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM