![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programmer
Join Date: Oct 2005
Posts: 48
Rep Power: 0
![]() |
void Processfile()
{
char FileName[] = "C:\\abc.txt";
while( true)
{
if (fexists(FileName))
{
printf("File Exist\n\n");
ifstream infile("C:\\abc.txt");
string sLine = "";
while( getline(infile, sLine) )
{
if( strlen(sLine.c_str()))
{
printf( "%s\n", sLine.c_str());
}
}
DeleteFile();
}
else
{
printf( "Not Exist\n\n" );
}
}
}This function, i need to create it as a thread... I do this DWORD d_threadID = 0; CreateThread(NULL, 0, Processfile, NULL, 0, (LPDWORD)&d_threadID); Error Quote:
:o |
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,224
Rep Power: 5
![]() |
The error message is fairly self explanatory. The third argument of CreateThread is a pointer to a function that accepts one argument of type void * and returns an unsigned long. The compiler is complaining because you have attempted to pass it a function that accepts no arguments and returns void.
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Oct 2005
Posts: 48
Rep Power: 0
![]() |
still can not understand..... please guide...
|
|
|
|
|
|
#4 |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
I guess this is Win32 API?
You need to use a specific prototype/calling convention for your thread procedure. DWORD WINAPI ThreadProc( LPVOID pVoid ) |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Oct 2005
Posts: 48
Rep Power: 0
![]() |
ok.. i add (LPTHREAD_START_ROUTINE) for the 3th parameter...
DWORD d_threadID = 0; CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Processfile, NULL, 0, (LPDWORD)&d_threadID); Now there is no error.. BUTTTT... :o Why the process file did not run? What's wrong???? Anybody see what wrong? please inform.. your help will be very much appreciate... void Processfile()
{
char FileName[] = "C:\\abc.txt";
while( true)
{
if (fexists(FileName))
{
printf("File Exist\n\n");
ifstream infile("C:\\abc.txt");
string sLine = "";
while( getline(infile, sLine) )
{
if( strlen(sLine.c_str()))
{
printf( "%s\n", sLine.c_str());
}
}
DeleteFile();
}
else
{
printf( "Not Exist\n\n" );
}
Sleep(200);
}
} |
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,224
Rep Power: 5
![]() |
Sigh. As I said earlier, your function ProcessFile() takes no arguments and returns void. It needs to accept a void pointer and return an unsigned long.
unsigned long ProcessFile(void *)
{
// the body of your function
}Using a cast, as in CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Processfile, NULL, 0, (LPDWORD)&d_threadID); In this case it would also be a good idea to eliminate the (LPDWORD) cast as well from your call. Telling the compiler that &d_threadID is a pointer to a DWORD does not magically turn d_threadID into a DWORD. Last edited by grumpy; Mar 14th, 2006 at 5:50 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|