Solution to the prompt "not declaring identifier" when using the control

Source: Internet
Author: User

Problem proposal: In the MFC extension DLL program, a new dialog box named idd_dialog 1 and three text editing controls named idc_sigm, idc_ratiolow, and idc_ratiohigh are created. A dialog box class (derived from the cdialog class) is created ). The code for Control Reference is as follows:

Enum {IDD = idd_dialog1 };


Ddx_text (PDX, idc_sigma, m_sigma );

Ddx_text (PDX, idc_ratiolow, m_ratiolow );

Ddx_text (PDX, idc_ratiohigh, m_ratiohigh );

The following error is prompted during compilation:

Error c2065: "idc_ratiohigh": Undeclared identifier (other controls share the same error, which is omitted here ).


Solution:

For this error, the control is undefined. Why is this error? Because the IDs of these controls are all function parameters, we usually look at the function definition. Let's look at the definition of the ddx_text function in msdn:

 

Void afxapi ddx_text (cdataexchange *PDX, IntNIDC, Byte &Value);

The last parameter "value" can also be another data type (such as int, long ...).

Check resource. h to see if there are any definitions of these spaces. The Code is as follows:

 

# Define idd_dialog1 5000

# Define idc_sigma 5000

# Define idc_ratiolow 5001

# Define idc_ratiohigh 5002

Since there is still an error in the definition, I first want to include the specific value of the definition to try, so I changed Enum {IDD = idd_dialog1} To Enum {IDD = 5000 }, make similar changes to other error statements. When the link is compiled, no error is prompted. I thought the problem was solved. In fact, it was even worse.

In this way, there is no problem in modifying the compilation link, because it is defined by definition. As for whether the variable m_sigma cannot be passed into the corresponding text control, I don't know. I can do a test if I have time. So it passes. However, when you use the "Class Wizard" to add an Event Response Message to the "OK" button in the dialog box, an exception is prompted. The problem has not been solved.

Think about it, since it is defined in "resource. H ", will not contain this header file, because the dialog box enables us to create," resource. H "is automatically added along with the dialog box. Of course, it is not automatically included in. CPP or. in the H file, "resource. H "defines the new dialog box class, which does not contain" resource. h. It seems that the problem has been solved. Add Resource. H to the header file of stdafx. h or dialog box class.

# Include "resource. H"

As a result, the compilation link is passed, and no exception will occur when the event response is added to the control.


Summary: This is a very common problem. I have encountered it before. I will write it down here to remind myself of it, note that when there is a problem with similar non-definition, first consider whether the definition is included in other header files without including the file.

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.