{"id":23953,"date":"2008-01-02T10:00:00","date_gmt":"2008-01-02T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/01\/02\/you-know-the-answer-window-destruction\/"},"modified":"2008-01-02T10:00:00","modified_gmt":"2008-01-02T10:00:00","slug":"you-know-the-answer-window-destruction","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080102-00\/?p=23953","title":{"rendered":"You know the answer: Window destruction"},"content":{"rendered":"<p>\nThe following request for assistance came in from a customer,\nand given what you know about window destruction,\nyou should eventually be able to figure it out yourself once all the\npieces are in place,\nthough it takes some time for all the clues to be revealed.\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nWe are hitting this exception in our program.\nThis is urgent; please give it priority attention.\n<\/p>\n<pre>\n0006f6ac kernel32!InterlockedCompareExchange+0xc\n0006f6ec comctl32!CImageListBase::IsValid+0x2a\n0006f6fc comctl32!HIMAGELIST_QueryInterface+0x2c\n0006f714 comctl32!ImageList_GetBkColor+0x1b\n0006f724 comctl32!TV_HasTransparentImage+0x1c\n0006f744 comctl32!TV_SelectItem+0x1a\n0006f7d4 comctl32!TV_DeleteItemRecurse+0x12a\n0006f85c comctl32!TV_DeleteItemRecurse+0x58\n0006f87c comctl32!TV_DeleteItem+0x8c\n0006f89c comctl32!TV_DestroyTree+0x90\n0006f900 comctl32!TV_WndProc+0x2e7\n0006f92c USER32!InternalCallWinProc+0x23\n0006f9a4 USER32!UserCallWinProcCheckWow+0x14b\n0006fa00 USER32!DispatchClientMessage+0xda\n0006fa28 USER32!__fnDWORD+0x24\n0006fa54 ntdll!KiUserCallbackDispatcher+0x2e\n0006fa58 USER32!NtUserDestroyWindow+0xc\n0006faac comctl32!_RealPropertySheet+0x307\n0006fac0 comctl32!_PropertySheet+0x45\n0006fad0 comctl32!PropertySheetW+0xf\n0006fbc4 abc!Wizard::ModalExecute+0x17c\n0006fc50 abc!RunWizard+0x564\n0006fcac abc!Start+0x185\n0006fd70 abc!ABCEntryW+0x2b9\n0006ff5c abc!wmain+0x7db\n0006ffa0 abc!__tmainCRTStartup+0x10f\n0006ffac kernel32!BaseThreadInitThunk+0xe\n0006ffec ntdll!_RtlUserThreadStart+0x23\n<\/pre>\n<\/blockquote>\n<p>\nThe proximate problem is that the treeview control is trying\nto use an imagelist that is no longer valid,\nprobably because it has already been destroyed.\nIf you look at the stack, you can see that the treeview\ncontrol is being destroyed.\nYou might infer this from the function named\n<code>TV_DestroyTree<\/code>,\nor if you look at the parameters, which I removed from the\nstack trace for brevity, you would see that\nthe message is <code>WM_DESTROY<\/code>.\n<\/p>\n<p>\nThe next step in unwinding the problem is figuring out\nwho destroyed the imagelist while it was still in use.\nThe customer shared their source code, and a little bit\nof spelunking revealed that it was this function\nwhich destroyed the imagelist:\n<\/p>\n<pre>\nvoid\nXYZPage::OnDestroy()\n{\n   if (m_hImageList)\n   {\n      ImageList_RemoveAll(m_hImageList);\n      ImageList_Destroy(m_hImageList);\n   }\n}\n<\/pre>\n<p>\nNow all the clues to the puzzle have been laid out on the table.\nUse your fantastic powers of deduction to see where the customer\nwent wrong.\nTo refresh your memory, you might want to read\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/07\/26\/443384.aspx\">\nthis old blog entry<\/a>.\n<\/p>\n<p>\n(And now that you&#8217;ve seen and understood this problem,\nin the future you can jump from the stack trace directly to the\nconclusion,\nthereby exhibiting your psychic debugging powers.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following request for assistance came in from a customer, and given what you know about window destruction, you should eventually be able to figure it out yourself once all the pieces are in place, though it takes some time for all the clues to be revealed. We are hitting this exception in our program. [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-23953","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The following request for assistance came in from a customer, and given what you know about window destruction, you should eventually be able to figure it out yourself once all the pieces are in place, though it takes some time for all the clues to be revealed. We are hitting this exception in our program. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=23953"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23953\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=23953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=23953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=23953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}