Wednesday, October 17, 2007

[VC++ 6.0] Getting 0xC0000005 Access Violation from CFileDialog - Troubleshootin' ain't no joke

Problem: You get an Access Violation when using CFileDialog and you have the February 2003 Platform SDK.
Solution(s):
  1. Uninstall the Platform SDK *
  2. In VS6 go to Tools->Options choose the Directories tab. Remove from the list the Platform SDK includes and libs folders (if you have a mess in there and you are not able to find the PlatformSDK ones you might wanna leave only the VS98 ones, but you should know this would be butchering) *
  3. Instead of using CFileDialog the usual way (at least the most common) use new and delete operators

*Remember to do a good Rebuild All, otherwise it would keep going with the old headers.

Another gift from our MS butchers here. This problem seems to be related to some member of some struct in some header of the Platform SDK which doesn't match with the header shipped with VC++. Quoting from one of the forum buddies "the OPENFILENAME-struct is longer in the header-file of the SDK than in the header-files shipped with VC++. So a memset(&m_ofn, 0, sizeof(m_ofn)); overwrites some data which leads to a crash", or something like that.

This is a tricky one because actually it will take you some time to figure out that the Access Violation is related to the CFileDialog (you wouldn't think of that, why should the CFileDialog stop working like that?). Moreover, if you have the Platform SDK installed since a long time definitely you wouldn't connect the three elements: Platform SDK - CFileDialog - Access Violation. It could be a known issue (it is indeed), but if you google just Access Violation you will obviously get a helluva result set.

A bit of a pain in the ass I'd say.

3 comments:

Depakra said...

thanks, this post was really useful to me.

Johnny Idol said...

happy to hear that.

Jose Rojas said...

Add in stdafx.h

#define _WIN32_WINNT 0x400 //so that
I can use ReadDirectoryChanges