Function not working in other thread

Hi, I am trying to run FtpGetFile function in another thread, and it not working correctly. That's how I create thread:
 
_beginthread	( _putfile, 0, NULL );


And that function:
1
2
3
4
5
6
7
8
9
10
void	_putfile ( void * ch )
{
	if ( FtpPutFile ( FTP, TEXT ( "file2.txt" ), TEXT ( "file2.txt" ), FTP_TRANSFER_TYPE_BINARY, 0 ) )
	{
		
	}
	else
		// fail

}


Everything seems correct, because when I try to use that code not in threading, then it works perfectly. I used 'GetLastError', after 'FtpPutFile' finishes, and I get 'Invalid handle', but handle is correct, because it works everywhere else.
try to create the handle in the same thread where it runs.
Thanks, it worked. But I don't get, why I need to connect to internet and ftp again?
One possible explanation is that each thread has its own stack. It may happen that the connection object was created in one thread's stack and it has been destroyed at the time when it is used in the other thread.
Topic archived. No new replies allowed.