-
December 24th, 2009, 04:10 AM
#1
My thread class not working
Error given :
Error 1 error C3867: 'GenericThread::ThreadProc': function call missing argument list; use '&GenericThread::ThreadProc' to create a pointer to member ...\GenericThread\GenericThread.cpp 19
IDE : MS Visual Studio 2005
GenericThread.h
Code:
#pragma once
#include <Windows.h>
class GenericThread
{
public:
GenericThread();
~GenericThread();
// Create and run the thread
void Start(LPVOID lpParameter, int nPriority = 0, bool create_suspended = false, SIZE_T stack_size = 0, bool reserve_stack = false);
// This member function will run when you call StartThread()
DWORD WINAPI ThreadProc(LPVOID lpParameter);
// -15 : lowest; +15 : highest
void SetPriority(int nPriority);
// Get currently assigned priority level
int GetPriority();
// Get thread status
bool IsRunning();
// Pause execution
void Suspend();
// Resume execution
void Resume();
// Terminate execution
void Terminate();
// Return thread handle
HANDLE GetHandle();
private:
// Handle to the thread
HANDLE m_hThread;
// The thread id assigned by Windows, there is no use for now
LPDWORD m_lpdwThreadID;
// You can use this property to signal the ThreadProc() to prepare for termination
bool m_bExiting;
// Thread status
bool m_bRunning;
};
GenericThread.cpp
Code:
#include "GenericThread.h"
GenericThread::GenericThread()
{
m_bExiting = false;
m_bRunning = false;
}
GenericThread::~GenericThread()
{
if (m_bRunning) CloseHandle(m_hThread);
}
void GenericThread::Start(LPVOID lpParameter, int nPriority /*= 0*/, bool create_suspended /*= false*/, SIZE_T stack_size /*= 0*/, bool reserve_stack /*= false*/)
{
DWORD dwCreationFlags = 0;
if (create_suspended) dwCreationFlags |= CREATE_SUSPENDED;
if (reserve_stack) dwCreationFlags |= STACK_SIZE_PARAM_IS_A_RESERVATION;
m_hThread = CreateThread(NULL, stack_size, ThreadProc, lpParameter, dwCreationFlags, m_lpdwThreadID); // ERROR GIVEN ON THIS LINE
SetPriority(nPriority);
m_bRunning = true;
}
DWORD WINAPI GenericThread::ThreadProc(LPVOID lpParameter)
{
while (true) Sleep(60000);
return 0;
}
void GenericThread::SetPriority(int nPriority)
{
SetThreadPriority(m_hThread, nPriority);
}
int GenericThread::GetPriority()
{
return GetThreadPriority(m_hThread);
}
bool GenericThread::IsRunning()
{
return m_bRunning;
}
void GenericThread::Suspend()
{
SuspendThread(m_hThread);
}
void GenericThread::Resume()
{
ResumeThread(m_hThread);
}
void GenericThread::Terminate()
{
CloseHandle(m_hThread);
m_bRunning = false;
}
HANDLE GenericThread::GetHandle()
{
return m_hThread;
}
-
December 24th, 2009, 04:35 PM
#2
Re: My thread class not working
Code:
#pragma once
#include <Windows.h>
class GenericThread
{
public:
GenericThread();
~GenericThread();
// Create and run the thread
void Start(LPVOID lpParameter, int nPriority = 0, bool create_suspended = false, SIZE_T stack_size = 0, bool reserve_stack = false);
// This member function will run when you call StartThread()
static DWORD WINAPI ThreadProc(LPVOID lpParameter);
//...
-
December 24th, 2009, 04:47 PM
#3
Re: My thread class not working
![Quote](images/misc/quote_icon.png) Originally Posted by hoxsiew
Code:
#pragma once
#include <Windows.h>
class GenericThread
{
static DWORD WINAPI ThreadProc(LPVOID lpParameter);
Yeah, it mysteriously works when I add the "static" keyword.
But why, what is the logic behind this?
-
December 24th, 2009, 04:54 PM
#4
Re: My thread class not working
Without it, since your ThreadProc function is a member of the GenericThread class, it has an implicit "this" pointer as the first parameter. As such, it doesn't match the function argument for CreateThread.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|