Home > Software engineering >  The variables in the class, thread gets less than?
The variables in the class, thread gets less than?

Time:10-04


Class A
{
Public:
Void Init (char * STR, int a);
Friend UINT _stdcall Begin (void * p);
Char m_str [260].
};
A, ga.

Button:
Ga. The Init (SSSS, 5);
Sleep (1000);
_beginthreadex (0, 0, the Begin, (LPVOID) & amp; The gA, 0, 0);

The thread function
UINT _stdcall Begin (void * p)
{
A * pa=(A *) p;
Char s1 [260];
Strcpy (s1, pa - & gt; M_str); This is how to obtain ""? No string?

return 0;
}

CodePudding user response:

Void A: : Init (char * STR, int A)
{
Strcpy (m_str, STR);
}

CodePudding user response:

 
# include & lt; Process. H>
Class A
{
Public:
Void Init (char * STR, int a)
{
Strcpy (m_str, STR);
}
Friend UINT _stdcall Begin (void * p);
Char m_str [260].
};

A, ga.

UINT _stdcall Begin (void * p)
{
A * pa=(A *) p;
Char s1 [260];
Strcpy (s1, pa - & gt; M_str);
AfxMessageBox (s1);
//
return 0;
}

Void CAboutDlg: : OnButton1 ()
{
//TODO: Add your the control notification handler code here
Ga. The Init (SSSS, 5);
//Sleep (1000);
_beginthreadex (0, 0, the Begin, (LPVOID) & amp; The ga, 0, 0);
}

CodePudding user response:

Void Init (char * STR, int a) what's the use of the five?

CodePudding user response:

Transfer data. If no problem program. The CPU, memory card. Thread has a writing data, get the string data to.

CodePudding user response:

Take a look at your real void Init (char * STR, int a)

CodePudding user response:

Find out why... Wild didn't p=NULL pointer to release

CodePudding user response:

Out of memory... One afternoon and evening

CodePudding user response:

The
references to the body of the 6th floor, I am your response:
find out why... Wild pointer is released when no p=NULL
you post the program did not reflect this ah, where need p=NULL?

CodePudding user response:

You pass A pointer in the past if A ga is A global, there is no problem, if it is local, object can be released in system before you visit,
You are illegal memory access,
  • Related