Guodandan
May 19th, 1999, 03:25 AM
Hi all there.
I am programming a DLL with MFC library statically linked using VC6. The DLL exports a function named BeginMonitor(), which starts a thread by calling AfxBeginThread() to do the actual real-time monitoring work. This DLL is implicitly linked into my application.
Within the thread function, the code looks like following:
UINT MonitorThread(LPVOID)
{
CInternetSession is;
CFtpConnection *pFtp=is.GetFtpConnection(...);
CInternetFile *pFile;
UINT i;
do{
pFile=pFtp->OpenFile(lpszFileName); //here opens target file on FTP server
pFile->SetReadBufferSize(256); //set the read buffer size
pFile->Read(&i, 4); //here reads the first 4 bytes into i
... //other routines
pFile->Close();
delete pFile;
// wait 5 seconds before next round monitoring, or quit loop if
// g_eveQuitMonitor.SetEvent() is called. (g_eveQuitMonitor is
// a global defined CEvent variable in the DLL)
}while(::WaitForSingleObject(g_eveQuitMonitor, 5000)!=WAIT_OBJECT_0);
... // other routines to disconnect FTP connection.
} //end of monitor thread
I had wished that by do..while.. looping, the pFile can be refreshed every time when the target file (named by lpszFileName) is newed. Unfortunately, it is not. Actually, by doing pFile->Read() operation, it always reads the same value into i as it reads the first time, no matter how I change the first 4 bytes of the target file. Even when the g_eveQuitMonitor.SetEvent() is called and the thread is exited, and when re-enter the thread by calling BeginMonitor() again, pFile still ignores the new target file and return the old value. Unless I restart my application, the new target file will always be ignored. Annoy!
So, could anybody give me a hint about how to use CInternetFile correctly, or tell me that is a bug of M$? :( Thank you very much for any kind of help from you.
mailto://chinaufo@263.net
I am programming a DLL with MFC library statically linked using VC6. The DLL exports a function named BeginMonitor(), which starts a thread by calling AfxBeginThread() to do the actual real-time monitoring work. This DLL is implicitly linked into my application.
Within the thread function, the code looks like following:
UINT MonitorThread(LPVOID)
{
CInternetSession is;
CFtpConnection *pFtp=is.GetFtpConnection(...);
CInternetFile *pFile;
UINT i;
do{
pFile=pFtp->OpenFile(lpszFileName); //here opens target file on FTP server
pFile->SetReadBufferSize(256); //set the read buffer size
pFile->Read(&i, 4); //here reads the first 4 bytes into i
... //other routines
pFile->Close();
delete pFile;
// wait 5 seconds before next round monitoring, or quit loop if
// g_eveQuitMonitor.SetEvent() is called. (g_eveQuitMonitor is
// a global defined CEvent variable in the DLL)
}while(::WaitForSingleObject(g_eveQuitMonitor, 5000)!=WAIT_OBJECT_0);
... // other routines to disconnect FTP connection.
} //end of monitor thread
I had wished that by do..while.. looping, the pFile can be refreshed every time when the target file (named by lpszFileName) is newed. Unfortunately, it is not. Actually, by doing pFile->Read() operation, it always reads the same value into i as it reads the first time, no matter how I change the first 4 bytes of the target file. Even when the g_eveQuitMonitor.SetEvent() is called and the thread is exited, and when re-enter the thread by calling BeginMonitor() again, pFile still ignores the new target file and return the old value. Unless I restart my application, the new target file will always be ignored. Annoy!
So, could anybody give me a hint about how to use CInternetFile correctly, or tell me that is a bug of M$? :( Thank you very much for any kind of help from you.
mailto://chinaufo@263.net