0

I'm using MFC for writing a windows program. I have used these settings when creating the project.
File -> New Project -> MFC applicatioin
and in the MFC application wizard I have choosed:
Application type: Dialog based
Resource language: English (United States)
Use Unicode libraries
Project style: MFC standard
Use of MFC: Use MFC in a static library
Main frame styles: Thick frame, System menu and About box are ticked
Advanced features: ActiveX controls, Common Control Manifest and Support Restart Manager are ticked
Dialog title: P2
Generated classes: Cp2App and Cp2Dlg
I haven't add any codes to the project yet. And I have just been adding the controls in the form:

enter image description here
but when I try to run the project, I get the errors:
1-error LNK2001: unresolved external symbol "public: void __thiscall CP2Dlg::OnBnClickedButton2(void)" (?OnBnClickedButton2@CP2Dlg@@QAEXXZ)
2-error LNK1120: 1 unresolved externals
I know that I can start a new project to avoid the error. But I want to know what causes this problem and solve it?

Note: the first error occurs in the P2Dlg.obj and the second occurs in the P2.exe file.

Edited section: In fact I think this error is because I carelessly double-clicked Button2 and created the eventhandler BnClickedButton2 and deleted it. Now I try to create this eventhandler again but I can't, Because when I right-click button2 and choose add eventhandler in the event handler wizard the option BN_CLICKED is inactive.
I want to know how to generally fix this kind of problems.Please help me?

Edited section 2: I have added this function in the P2.cpp file using Add EventHandler but this did not solve the problem:

void CP2App::OnBnClickedButton2()
{
    // TODO: Add your control notification handler code here
}  

the function CP2Dlg::OnBnClickedButton2 should be added but I can't add it. It is inactive?????

2

1 Answer 1

0

There is a line in the dialog's message map that attempts to call the function you deleted. In the future if you delete a message handler function also delete the corresponding entry in the message map.

The message handler must be in the dialog class. (That's where the message is sent.) Clean out the message map and function and rebuild all. Then you can probably get the Add Event wizard working again.

1
  • @sepideh You delete the message map by removing its declaration DECLARE_MESSAGE_MAP() and implementation BEGIN_MESSAGE_MAP(cls,base) ... END_MESSAGE_MAP(). I have no idea why you would want to do that. Jul 19, 2013 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.