stephenprogrammer07
July 25th, 2007, 09:28 PM
Hi
I'm a newbie of sorts with C++ multithreading.
I am trying to figure out how to pass a char* to my Thread.
I'm using the following code.
class CFoo
{
public:
CFoo()
{
m_dwThreadID = 0;
m_hThread = 0;
}
~CFoo() { CloseHandle(m_hThread); }
bool Create()
{
m_hThread = CreateThread(0,
0,
ThreadFunc,
this,
0,
&m_dwThreadID);
if(!m_hThread)
{
// Could not create thread
return false;
}
return true;
}
HANDLE TheHandle(void) const { return m_hThread; }
private:
DWORD m_dwThreadID;
HANDLE m_hThread;
static DWORD WINAPI ThreadFunc(LPVOID pvParam);
};
DWORD WINAPI CFoo::ThreadFunc(LPVOID pvParam)
{
// Wait for 10 seconds.
for(int i = 0; i < 10; i++)
{
std::cout << "Start thread" << std::endl;
::Sleep(100);
}
return 0u;
}
I read that, the 4th parameter is how you pass a parameter to ThreadFunc.
But when I try to pass in a "test string" it doesn't compile.
m_hThread = CreateThread(0,
0,
ThreadFunc,
"test String",
0,
&m_dwThreadID);
Any thoughts ?
Thanks
Stev
I'm a newbie of sorts with C++ multithreading.
I am trying to figure out how to pass a char* to my Thread.
I'm using the following code.
class CFoo
{
public:
CFoo()
{
m_dwThreadID = 0;
m_hThread = 0;
}
~CFoo() { CloseHandle(m_hThread); }
bool Create()
{
m_hThread = CreateThread(0,
0,
ThreadFunc,
this,
0,
&m_dwThreadID);
if(!m_hThread)
{
// Could not create thread
return false;
}
return true;
}
HANDLE TheHandle(void) const { return m_hThread; }
private:
DWORD m_dwThreadID;
HANDLE m_hThread;
static DWORD WINAPI ThreadFunc(LPVOID pvParam);
};
DWORD WINAPI CFoo::ThreadFunc(LPVOID pvParam)
{
// Wait for 10 seconds.
for(int i = 0; i < 10; i++)
{
std::cout << "Start thread" << std::endl;
::Sleep(100);
}
return 0u;
}
I read that, the 4th parameter is how you pass a parameter to ThreadFunc.
But when I try to pass in a "test string" it doesn't compile.
m_hThread = CreateThread(0,
0,
ThreadFunc,
"test String",
0,
&m_dwThreadID);
Any thoughts ?
Thanks
Stev