Solve the problem of an error in the open file dialog box of the MFC program.

Source: Internet
Author: User

Solve the problem of an error in the open file dialog box of the MFC program.

A few days ago, I posted an image analysis mfc applet from the Internet, which is from VC6.

It is okay to compile and generate the program locally using VC6. An unhandled error pops up and the program crashes and exits.

I think that I had encountered a problem in opening the file dialog box. At that time, the project was too short to go into details.

Please take a good look at this issue this time.

The specific method is to follow up, track, and track carefully...

Application code, follow up

MFC code, follow up

Alt + 8 call out disassembly, follow up...

Repeat and trace the target multiple times to narrow down the target. The problem is that the CString destructor is called in the CFileDialog destructor,

It is precisely because the analysis structure CSring has an error.

The definition of CFileDialog is as follows, which indicates that the m_strFilter fails to be parsed.
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 );

....... N multiple rows are omitted

Protected:
BOOL m_bOpenFileDialog; // TRUE for file open, FALSE for file save
CString m_strFilter; // filter string
// Separate fields with '|', terminate with '| \ 0'
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 );
};

The m_strFilter address found here is incorrect.

0012F7EC is the address of the CFileDialog instance.

The analysis structure m_strFilter looks for 0012F8A8, and an error occurs when it is executed again. It seems wrong to take a look at this address.

Therefore, when constructing function tracking, it is found that the m_strFilter address is 0012F89C.

When comparing the this pointer of m_strFilter in ecx, it is obviously different.

Add ecx 0b0h; during construction

Add ecx 0bch; destructor

Oh, well, how can it be different when calculating the offset? So, let's take a moment to study it.

Sorry, someone may have studied it. A brainwave: bing's "add ecx 0b0h". Sure enough, the first hit

Http://blog.titilima.com/show-590-1.html. Thank you, Mr. Li Ma :-)

The reason is clear.

But how to change it? Do you need to change the source code of.

Of course, the source code of VS can also be changed. However, we found that

C: \ Program Files \ Microsoft SDKs \ Windows \ v7.1 \ Include

At the time of MFC4.2, there should be no v7.1 version. Let's check the directory settings.

Include v7.1 to the top.

Move to the bottom of the list and generate all the items again. No problem, either.

Can't you remember this setting, or will it be affected when VS2010 or DDK is installed ??

In short, we can think that VC6 itself is still okay. The conflict caused by installing multiple development environments is the cause of this problem.

Zookeeper

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.