This can be pretty tricky to dig into because all kinds of 3rd party applications and tools can have attached themselves to the dialog. You can also experience different behavior depending on which version of Windows you are running on. I have listed a number of approaches below that you can try out.
1 - Calling CoInitializeEx(COINIT_MULTITHREADED)
First you should look into the solution posted as a message to an article here on CodeProject:
XFolderDialog - a folder selection dialog based on CFileDialog[
^]. He found the fix after reading this article:
http://support.microsoft.com/kb/287087[
^].
2 - Sloppy code, such as not releasing the buffer after calling CString::GetBuffer()
It is also possible that you have not shown us all the relevant code and your problem is similar to what was fixed in Jochen Arndt's answer here:
cFileDialog DoModal Exception[
^].
3 - Turn off Vista Style
Another option is to try to not show the dialog in "Vista Style":
http://social.msdn.microsoft.com/Forums/vstudio/en-US/0e8762c9-cc99-49ec-9c06-4c6824114db9/riddle-me-this-domodal?forum=vcgeneral[
^]
4 - Tracking down faulty 3rd party extension
If none of the above approaches helped you solve the problem, you need to look at the 3rd party applications and tools that have their hooks into the dialog. See these articles:
http://mfctips.com/2012/10/29/cfiledialogdomodal-causes-access-violation/[
^]
http://computer-programming-forum.com/82-mfc/f4f6bf48f940e6eb.htm[
^]
Soren Madsen