Read MSDN carefully

Posted on June 30, 2008. Filed under: Debugging |

John Robbins had warned about this in his debug war stories: read MSDN carefully.
We missed this and ended up with crash.

Details:
MSDN says "GetDlgItem() returns pointer which is temporary and should not be saved and used later." Well this remark didn’t catch the eye because we anyway use the pointer in the same method and never save it.

So, naturally, we ignored this and did what it warned against. We got pointer to dialog control. Before using it though, of course in the same method,
we did some calls which invoked COM objects. After this we used the CWnd* pointer to enable the window and !BOOOOM!.. WER flashed.
Invocation of this COM object somewhere deep down has overwritten memory pointed by CWnd* returned by GetDlgItem(). Solution was to call GetDlgItem() and use the pointer immediately.

Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

2 Responses to “Read MSDN carefully”

RSS Feed for A Glitch in Code Takes Nine Department Comments RSS Feed

[…] – bookmarked by 1 members originally found by WaitJustASecond on 2008-07-21 Read MSDN carefully https://shellexecute.wordpress.com/2008/06/30/read-msdn-carefully/ – bookmarked by 1 members […]

Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: