Click here to Skip to main content
15,896,730 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Owner drawn button flicker hell Pin
Rick Dangerous2-Jan-02 0:30
Rick Dangerous2-Jan-02 0:30 
GeneralRe: Owner drawn button flicker hell Pin
Christian Graus2-Jan-02 0:52
protectorChristian Graus2-Jan-02 0:52 
Generalmalloc() question Pin
1-Jan-02 17:26
suss1-Jan-02 17:26 
GeneralRe: malloc() question Pin
Philip Patrick1-Jan-02 19:14
professionalPhilip Patrick1-Jan-02 19:14 
GeneralRe: malloc() question Pin
1-Jan-02 19:15
suss1-Jan-02 19:15 
GeneralRe: malloc() question Pin
Philip Patrick1-Jan-02 19:23
professionalPhilip Patrick1-Jan-02 19:23 
Generalremove popup menu arrow Pin
1-Jan-02 15:35
suss1-Jan-02 15:35 
GeneralProblem with Multithreads Pin
Mustafa Demirhan1-Jan-02 6:06
Mustafa Demirhan1-Jan-02 6:06 
Hi,

I am programming a multithreaded application however I am having lots of difficulties this week. I programmed many multithreaded applications but in this program I am really stucked. There is a main View class (say CMyView). This class have a CTaskManager class, which controls all the threads. The threads are called CTaskThread. Each CTaskThread need to call methods of CTaskManager. Here is the problematic part of the code:

class CTaskManager  
{
public:
	CTaskManager ();
	virtual ~CTaskManager ();
protected:
	CString m_sSharedVars [MAX_VARS];
        
        ...
};

void CTaskManager::ReplaceVariables (CString &str)
{
	for (int i = 0 ; i < MAX_VARS ; i++)
	{
		if (m_sSharedVarNames [i] != m_sSharedVars [i])
		{
			while (str.Replace (m_sSharedVarNames [i], m_sSharedVars [i]) != 0);
		}
	}
}


When I run the program, it crashes at line m_sSharedVarNames [i] != m_sSharedVars [i]. In fact, it crashes whenever it tries to acces the elements of CTaskManager. However, when I remove the definition CString m_sSharedVars [MAX_VARS]; from the class and write it to the beginning of the CPP file (i.e. make it global), the program works fine. But the problem is that, I have to access other variables of CTaskManager, and I cannot make all of them global. The error message is the following:
<br />
The intruction at "0x5f47714c" referenced memeory at "0xcdcdcde1". The memory could not be "read". <br />
Click on OK to terminate the program<br />
Click on Cancel to debug the program<br />


When I click on Cancel and debug the program, it jumps to the following line in AFX.INL
<br />
_AFX_INLINE CString::operator LPCTSTR() const<br />
	{ return m_pchData; }<br />

The error is
<br />
Unhandled exception in MyProgram.exe (MFC42D.DLL):0xC0000005:Access Violation<br />


Please HELP. I am stucked and I dont know what to do. I tried to use CCriticalSection to protect the data to be read/written by more than one threads at the same time but it didnt worked. In fact, when I run only one thread, the program crashes again!

Kind regards
Mustafa Demirhan

http://www.macroangel.com

Sonork ID 100.9935:zoltrix
GeneralRe: Problem with Multithreads Pin
Mustafa Demirhan1-Jan-02 6:12
Mustafa Demirhan1-Jan-02 6:12 
GeneralRe: Problem with Multithreads Pin
1-Jan-02 6:32
suss1-Jan-02 6:32 
GeneralRe: Problem with Multithreads Pin
1-Jan-02 6:56
suss1-Jan-02 6:56 
GeneralRe: Problem with Multithreads Pin
Todd Smith1-Jan-02 7:35
Todd Smith1-Jan-02 7:35 
GeneralRe: Problem with Multithreads Pin
Mustafa Demirhan1-Jan-02 8:59
Mustafa Demirhan1-Jan-02 8:59 
GeneralRe: Problem with Multithreads Pin
Michael Dunn1-Jan-02 9:30
sitebuilderMichael Dunn1-Jan-02 9:30 
GeneralRe: Problem with Multithreads Pin
Mustafa Demirhan2-Jan-02 0:33
Mustafa Demirhan2-Jan-02 0:33 
GeneralCompatibility Question Pin
1-Jan-02 3:37
suss1-Jan-02 3:37 
GeneralRe: Compatibility Question Pin
Philip Patrick1-Jan-02 3:50
professionalPhilip Patrick1-Jan-02 3:50 
GeneralHi, Philip ,look here... Pin
1-Jan-02 5:42
suss1-Jan-02 5:42 
GeneralRe: Hi, Philip ,look here... Pin
Philip Patrick1-Jan-02 6:02
professionalPhilip Patrick1-Jan-02 6:02 
GeneralWM_ Pin
The_Server1-Jan-02 2:41
The_Server1-Jan-02 2:41 
GeneralRe: WM_ Pin
Philip Patrick1-Jan-02 2:55
professionalPhilip Patrick1-Jan-02 2:55 
GeneralRe: WM_ Pin
The_Server1-Jan-02 3:17
The_Server1-Jan-02 3:17 
GeneralRe: WM_ Pin
Philip Patrick1-Jan-02 3:41
professionalPhilip Patrick1-Jan-02 3:41 
GeneralRe: WM_ Pin
1-Jan-02 3:25
suss1-Jan-02 3:25 
GeneralRe: WM_ Pin
Philip Patrick1-Jan-02 3:43
professionalPhilip Patrick1-Jan-02 3:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.