Creating threads from a class
Hello, I have that problem: I try to create a new thread (on windows) with the api function 'CreateThread' from a function in a class; the thread procedure is a function private of the class, also the hanlde return, and the parameters passed. that's how I'm trying to do that (I have created a sample code to help my poor explanations :) ), that's it: first the main *.cpp file
Code:
#include <conio.h>
#include <stdio.h>
#include "asample.h"
CSample *sample;
int main()
{
sample=new CSample();
sample->start();
delete sample;
getch();
return 0;
}
now the 'asample.h' class header:
Code:
#include <windows.h>
#include <stdio.h>
class CSample
{
public:
CSample();
virtual~CSample();
void start();
private:
DWORD WINAPI crThr(LPVOID );
HANDLE ht;
DWORD ti;
};
and finally the 'asample.cpp' code:
Code:
#include "asample.h"
CSample::CSample()
{
ht=NULL;
}
CSample::~CSample()
{
}
void CSample::start()
{
th=CreateThread(NULL,0,crThr,0,0,&ti);
CloseHandle(ht);
}
DWORD WINAPI CSample::crThr(LPVOID lpParam)
{
printf("OK!\n");
}
the compiler says
Code:
In method `void CSample::start()':
12 no matches converting function `crThr' to type `DWORD (*)(void *)'
11 candidates are: DWORD CSample::crThr(void *)
[Build Error] [asample.o] Error 1
I have tryed to rename the function to:
'DWORD CSample::WINAPI crThr(LPVOID lpParam)'
but not solves the prob; also have done a call like:
'ht=(HANDLE)CreateThread(NULL,0,crThr,0,0,&ti);'
or
'ht=(DWORD WINAPI)CreateThread(NULL,0,crThr,0,0,&ti);'
and finally I have no idea on what more to do.
How can I salve that problem?
Thank's in advance
niara
PS I've decided to post here instead in windows board because I think that's a class problem, no a winapi prob.