-
August 22nd, 2013, 11:35 AM
#1
[RESOLVED] how call a procedure, like a new thread, with parameters?
heres my timer class(isn't a good thing, but works lol):
Code:
#include <Windows.h>
//for create a timer
class Timer
{
private:
int MilliSecondsTimer;
private:
bool blnDestroyed;
private:
HANDLE Handle_Of_Thread_1;
typedef void (*MyTimerProc)();
MyTimerProc TimerProcedure;
static DWORD WINAPI StaticThreadProc(LPVOID param)
{
static_cast<Timer*>(param)->MultithreadProcedure();
return 0;
}
public:
int SetMilliSeconds(int MilliSeconds)
{
MilliSecondsTimer = MilliSeconds;
return 0;
}
public:
int GetMilliSeconds()
{
return (MilliSecondsTimer);
}
private: void MultithreadProcedure()
{
for (;;)
{
if (blnDestroyed==true) break;
Sleep(MilliSecondsTimer);
TimerProcedure();
}
CloseHandle(Handle_Of_Thread_1);
TerminateThread( Handle_Of_Thread_1,1);
}
public:
int Start(MyTimerProc TimerProc(...))
{
TimerProcedure = TimerProc();
Handle_Of_Thread_1=0;
CloseHandle(Handle_Of_Thread_1);
TerminateThread( Handle_Of_Thread_1,1);
blnDestroyed=false;
HANDLE hMyThread;
hMyThread = CreateThread(NULL, 0, StaticThreadProc, this, 0, NULL);
return 0;
}
public: int Stop()
{
blnDestroyed=true;
return 0;
}
~Timer()
{
Stop();
}
};
imagine that the sub have some arguments, how can use them, when i call the sub?
see these sample:
Code:
Timer c; c.SetMilliSeconds(100);
c.Start( SetTextXY(10,10,"hello",100,500));
error message:
"IntelliSense: argument of type "void" is incompatible with parameter of type "Timer::MyTimerProc (*)(...)""
any advice?
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
|