Search code examples
c++atlwtl

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. 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). I get the same issue even if I use WTL 8.0.

Subclassing was done OK as HWND is valid. Any ideas?


Solution

  • WTL::CProgressBarCtrl m_Progress; <~ use that to attach the progress bar, not CContainedWindow.