Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm using a thread in a class but I don't know how I can call a function:

UINT ThreadProc(LPVOID pParam)
{
	CString strFile = CSc::CONFIG->PercFileScarico_K3();

	
	CFile cfile;
	cfile.Open(strFile, CFile::modeRead);
	CFileStatus status;
	cfile.GetStatus(status); //m_mtime 
	COleDateTime date(status.m_mtime.GetTime());

	
	if (date != CSc::CONFIG->GetDate())
	{
	    CSc::LeggiFileXMLDiScarico(); --> error in this row
		CSc::CONFIG->GetDate() = date;
	}
	return 0;
}


void CSc::AggiornTimer()
{	
    AfxBeginThread(ThreadProc, 0);
}







error is:
C2352 'CSc::LeggiFileXMLDiScarico': illegal call of non-static member function

What I have tried:

I tried to create an object, but I have error
Posted
Updated 1-Jun-23 0:59am
v2
Comments
Andre Oosthuizen 1-Jun-23 6:29am    
Non-static member functions can only be called on an instance of the class - Static Member Functions[^] - whereas static member functions are associated with the class itself and can be called without an instance.

Based on whether LeggiFileXMLDiScarico() depends on instance-specific data or not, you can create an instance of the CSc class or you can make LeggiFileXMLDiScarico() a static member function.

Static member functions[^]

1 solution

Possibly you need something like (not tested)
C++
UINT ThreadProc(LPVOID pParam)
{
    CSC * pcsc = reinterpret_cast<CSC*>(pParam); // added

	CString strFile = CSc::CONFIG->PercFileScarico_K3();
	
	CFile cfile;
	cfile.Open(strFile, CFile::modeRead);
	CFileStatus status;
	cfile.GetStatus(status); //m_mtime 
	COleDateTime date(status.m_mtime.GetTime());
	
	if (date != CSc::CONFIG->GetDate())
	{
	    pcsc->LeggiFileXMLDiScarico(); // changed
		CSc::CONFIG->GetDate() = date;
	}
	return 0;
}


void CSc::AggiornTimer()
{	
    AfxBeginThread(ThreadProc, this); //changed
}
 
Share this answer
 
v2
Comments
Member 14594285 1-Jun-23 8:34am    
software compile but I have this error after:
Unhandled exception thrown: read access violation.

this was 0x144.
CPallini 1-Jun-23 9:32am    
You should use the debugger to locate the problem.

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