Re: Unhandled exception - caused by not deleting vector?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Si wrote:
> UINT CChooseCampaignDlg::ThreadGetCampaigns(LPVOID pParam)
> {
> CChooseCampaignDlg* pDlg = static_cast<CChooseCampaignDlg*>(pParam);
> WPARAM wParam = (WPARAM) new
> vector<Campaign>(pDlg->manager.RequestCampaigns()); //line I provided
> earlier
> pDlg->PostMessage(UWM_MY_MESSAGE1, wParam, (LPARAM)0);
> return 0;
> }

I see a totally unrelated problem here: you can't use a CWnd* derived object
to send messages from a different thread, you need to use the plain win32
API here: PostMessage( pDsg->m_hWnd, UWM_MY_MESSAGE1, ...).

> The line of code it reaches when the crash happens is in the catch of the
> exception when it fails to connect :
>
> CATCH(CInternetException, pEx)
> {
> campaigns.push_back(Campaign(-1, _T("No campaign"))); //crash happens
> here!!!
> }

OK, if I understand you right, this is somewhere in the function
RequestCampain() of the manager object of the dialog. Of course, if you
close the dialog and the dialog object is destroyed, this will fail if it
is executed later. You need to prevent that from happening.

Put TRACE() macros in the ctors and dtors of all related classes and you
might see what is going on in what order.


BTW: you asked about a follow-up, this is used to direct traffic to just one
group and should be done when cross-posting to more than a group.

Uli

.



Relevant Pages

  • Re: CDialog::OnCopyData, what does it do?
    ... so the use of an HWND is NOT required at the sender site! ... LRESULT CWnd::SendMessage(UINT msg, WPARAM wParam, LPARAM lParam) { ... so it uses a CWnd *. ...
    (microsoft.public.vc.mfc)
  • Re: CDialog::OnCopyData, what does it do?
    ... so the use of an HWND is NOT required at the sender site! ... LRESULT CWnd::SendMessage(UINT msg, WPARAM wParam, LPARAM lParam) { ... so it uses a CWnd *. ...
    (microsoft.public.vc.mfc)
  • Catch WM_SIZE
    ... // m_MyControl derived from CWND ... LRESULT CMyDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) ...
    (microsoft.public.vc.mfc)