MFC Program Open File dialog box error problem resolution

Source: Internet
Author: User

A few days ago from the Internet under an image analysis of the MFC applet, is VC6

With VC6 in the local build is no problem, run up an unhandled error, the program crashes exit.

Think of the original encountered in the Open File dialog box, the project time was tense not to delve into.

This time we should take a good look at this problem.

Specific approach is to drill down, tracking, tracking ...

Application code, follow up

MFC code, follow up

Alt+8 recall disassembly, follow-up ...

Repeated repeated tracing, narrowing the target, to determine the problem is: in the CFileDialog destructor, called the CString destructor,

It is precisely the destruction of the csring error.

CFileDialog is defined as follows, that is, the destruction of this m_strfilter error.
Class Cfiledialog:public Ccommondialog
{
Declare_dynamic (CFileDialog)

Public
Attributes
OpenFileName m_ofn; Open File parameter block

Constructors
CFileDialog (BOOL bopenfiledialog,//TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = ofn_hidereadonly | Ofn_overwriteprompt,
LPCTSTR Lpszfilter = NULL,
cwnd* pParentWnd = NULL);

...... Omit n Multiple lines

Protected
BOOL M_bopenfiledialog; TRUE for File Open, FALSE for file Save
CString m_strfilter; Filter string
Separate fields with ' | ', terminate with ' | | "
TCHAR m_szfiletitle[64]; Contains file title after return
TCHAR M_szfilename[_max_path]; Contains full path name after return

Openfilename* m_pofntemp;

Virtual BOOL onnotify (WPARAM WPARAM, LPARAM LPARAM, lresult* pResult);
};

I found the address of the m_strfilter here is wrong.

0012F7EC is the address of the CFileDialog instance

Destruction m_strfilter looking for is 0012f8a8, then execution will be wrong, go to this address to glance, feel wrong AH

So when the constructor is traced, the address of the m_strfilter is found to be 0012f89c

When comparing the this pointer of m_strfilter in ECX two times, it is obviously different

add ecx 0b0h; construction time

add ecx 0bch; destructor

Oh, the offset, how can it be different, this, and then take the time to study it.

Now listen, someone might have studied it. Brainwave, Bing under "Add ecx 0b0h", sure enough, the first one will hit

Http://blog.titilima.com/show-590-1.html, here's the answer. Thank the author Mr. Li Ma:-)

The reason is very clear.

But how to change it, to move vs source code.

Of course, the source of the VS can be changed, but, through the definition of trace files found

C:\Program Files\Microsoft Sdks\windows\v7.1\include Below

Originally MFC4.2 era should not have v7.1 version of Ah, to see the directory setting it

V7.1 's include is at the top.

Decisive move to the bottom, all regenerate, no problem, AO also.

Have you ever moved this setting to remember, or later to install VS2010 or DDK when the impact??

In short, we can think that VC6 itself is not a problem, because the installation of multiple development environment caused by the conflict is the cause of this problem.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MFC Program Open File dialog box error problem resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.