Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a software with a library hooked and I must call a dialog of my library from software. I wrote:

C++
void CEstatisDlg::OnBnClickedButton2()
{
	CStatisToDayDlg *p = new CStatisToDayDlg;

	p->DoModal();
}


but I have this error:
Severity	Code	Description	Project	File	Line	Suppression State<br />
Error	LNK2019	unresolved external symbol "public: __thiscall CStatisToDayDlg::CStatisToDayDlg(class CWnd *)" (??0CStatisToDayDlg@@QAE@PAVCWnd@@@Z) referenced in function "public: void __thiscall CEstatisDlg::OnBnClickedButton2(void)" (?OnBnClickedButton2@CEstatisDlg@@QAEXXZ)	Estatis	C:\Dev2015\Prg\Estatis\EstatisDlg.obj	1


I don't know how I can call dialog.

What I have tried:

I changed code but I have error anyway:

C++
void CEstatisDlg::OnBnClickedButton2()
{
//	CStatisToDayDlg p;
//	p.Avvio(m_hWnd);

	CStatisToDayDlg * p = ( CStatisToDayDlg *) AfxGetMainWnd();

	p->DoModal();
}

Constructor:
C++
IMPLEMENT_DYNAMIC(CStatisToDayDlg, CDialog)

CStatisToDayDlg::CStatisToDayDlg(CWnd* pParent /*=NULL*/)
	: CDialog(IDD_DIALOG_STATISTODAY, pParent)
{
	time_t t = time(0);

	std::tm* now = localtime(&t);

	m_dataToday.SetDate((now->tm_year + 1900), 
                        (now->tm_mon + 1), now->tm_mday);

	m_ptrAdoDatabase = NULL;

	m_nConnessioneQuery = ADO_CONN_NONE;
}
Posted
Updated 19-Sep-23 10:37am
v7
Comments
Richard MacCutchan 18-Sep-23 10:18am    
You need to check that your call to the CStatisToDayDlg constructor is correct. The error message implies that it requires a pointer to a CWnd object. But without the full details of the library, and this specific class, there is not more that we can say.
Member 14594285 18-Sep-23 10:23am    
which detail do you need? So Must I call a CWnd pointer?
merano99 18-Sep-23 10:28am    
A CWnd object is a C++ window object, this applies to almost all under Windows. Here as basis a CDialog would be more appropriate.The error "unresolved external symbol" means something is missing or cant be found.
Richard MacCutchan 18-Sep-23 10:32am    
I have no idea, because I do not know the content of your library. So look at the header and source files to check how to call it.
Richard MacCutchan 18-Sep-23 10:46am    
There is nothing in that code to give a clue as to why it gives the link error. Are you sure that you are including the library in your project?

According to the code, you are already calling a modal dialog. Probably the question was rather how to create a dialog with Visual-Studio and include it in your own code?

The information how to create or use MFC dialog boxes can be read for free at Microsoft:

Working with Dialog Boxes in MFC
https://learn.microsoft.com/en-us/cpp/mfc/life-cycle-of-a-dialog-box
 
Share this answer
 
Comments
Member 14594285 18-Sep-23 10:30am    
but I have already diaog box, I must call it from software
merano99 18-Sep-23 10:50am    
If there is already a dialog, then there should be a header in which it is declared. Usually this is a dialog class directed by CDialog. The files belonging to the dialog must be added to the project. Then the header should be included with #include. The call can then be made with DoModal if it should be a modal dialog.

The header seems to be included, otherwise it would not know the constructor CStatisToDayDlg(class CWnd *). If the dialog is available as .cpp it must be included in the project. If it should be a library, this would have to be communicated to the linker. There are many details missing and so this becomes a guessing game.
You have not called the dialog's constructor correctly. You have :
C++
CStatisToDayDlg *p = new CStatisToDayDlg;
but the constructor's prototype indicates it requires a pointer to a parent window object which can be null. That needs to be addressed but


Your first error is from the linker. That error message states the code module that includes the dialog's code was not found by the linker. That is what "LNK2019 unresolved external symbol" means. There are typically two causes for that: either the library itself was not found or that code module was not included in the library.

Your second attempt :
C++
CStatisToDayDlg * p = ( CStatisToDayDlg *) AfxGetMainWnd();
will work only if an instance of the dialog is the main window for the application. If that is the case, then calling DoModal() will result in another instance of it and that does not seem like what you really want. Besides, if you haven't called its constructor correctly it won't work anyway.

You first need to address your linker error. Verify that the dialog's code is compiled as part of your library. Then verify that the library can be found by the linker. Often that requires adding a directory path for the library to your project's "Additional Libraries" property under linker options.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900