Use the MFC class in non-MFC

Source: Internet
Author: User
Tags what header

Reproduced in: http://hi.baidu.com/moonblind/item/8324e8a51f1920db5bf1910a

I. Problem Origin

The Project Wizard of vc6 and vc71 contains non-MFC projects, such as Win32 console project and Win32 static library. When a non-MFC project is created, it does not support the MFC feature. Then, when dealing with actual problems, we sometimes use MFC-related classes, such as cstring and cedit. This is normal. Some may say, why not create an MFC project at the beginning? The problem is that the MFC project will generate a lot of wizard Generation Code, for example, a single-document-based project will have a view, Doc, and other classes. In many cases, we only need an empty project.

Ii. FAQs

When using the MFC library for non-MFC projects, the most common problem is that windows. h contains repeated errors as follows:

Fatal error c1189: # error: Windows. h already supported ded. MFC APPs must not # include <windows. h>

Iii. Solution

When using the MFC library for a non-MFC project, follow these steps:

1. In Project Settings, change the use of MFC from the original "use standard Windows library" to "use MFC in shared DLL" (vc71)

If the English version is used, the related options are:

Microsoft Foundation Classes: use MFC in a shared DLL, no using MFC (vc6)

Note: I use the Chinese version of vc71 and the English version of vc6.

2. header file inclusion

Different MFC classes have different header files.

Common classes, such as cstring and cedit, include afxwin. h.

If you do not know what header files are included, You can query them with msdn. In msdn, the corresponding header file requirement will be provided for the introduction of the MFC class.

3. # The include statement must be written in the first line.

This is very important because the # include statement is not written in the first line.

Note that if the # include statement is in a header file, the header file must be included in the first line. Example:

==================

The content of the test. h file is as follows:

# Include <afxwin. h> // ensure that the statement is in the first line.

The content of the test. cpp file is as follows:

# Include "test. H" // make sure that the statement is in the first line

==================

PS: I don't know the specific reason for this. I figured this out in actual debugging. I spent a lot of time writing this article on this issue. I hope you will not be confused about this issue.

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.