0
votes

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?????

1
You should not ever try to use MFC without knowing Win32-Programming already. Charles Petzold is probably still the best resource to learn the latter. If/When you decide to start with MFC you should at the very least able to read the wizard-generated code. Jeff Prosise is mandatory reading for any MFC developer.IInspectable

1 Answers

0
votes

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.