|
Hi All,
Pls let me know if there is any solution for this problem.
Im starting FTP uploading and at the same time HTTP downloading too for the same server which supports both ftp and http.
File is partially downloading at the receiver.Downloaded file size is less than the actual uploaded file.
Here problem is internetreadfile() is failing to read, once it does not receive data while file is uploading.
m_hHttpFile = HttpOpenRequest(m_hHttpConnection, "GET", FileToDownload, NULL, NULL, ppszAcceptTypes, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_KEEP_CONNECTION, NULL);
if (m_hHttpFile == NULL)
{
return 0;
}
BOOL bSend = ::HttpSendRequest(m_hHttpFile, NULL, 0, NULL, 0);
if (!bSend)
{
AfxMessageBox(" Http download HttpSendRequest failed");
return 0;
}
TCHAR szStatusCode[32];
if (!HttpQueryInfo(m_hHttpFile, HTTP_QUERY_STATUS_CODE, szStatusCode, &dwInfoSize, NULL))
{
AfxMessageBox(" Http download HttpQueryInfo failed");
CString strMsg;
strMsg.Format("Error:%d", GetLastError());
//AfxMessageBox(strMsg);
return 0;
}
long nStatusCode = _ttol(szStatusCode);
if (nStatusCode != HTTP_STATUS_OK)
{
AfxMessageBox(" Http download server file not available ");
return 0;
}
DWORD dwBytesRead = 0;
char szReadBuf[TRANSFER_SIZE+1];
CFileException e;
m_FileToWrite.Open(LocalFile, CFile::modeCreate | CFile::modeWrite /*| CFile::shareDenyWrite*/);
double sum = 0;
do
{
if (!::InternetReadFile(m_hHttpFile, szReadBuf, TRANSFER_SIZE, &dwBytesRead))
{
AfxMessageBox("Http download InternetReadFile Failed");
return 0;
}
if(dwBytesRead>0)
{
TRY
{
m_FileToWrite.Write(szReadBuf, dwBytesRead);
}
CATCH(CFileException, e);
{
e->Delete();
return 0;
}
END_CATCH
}
sum += dwBytesRead;
}
while(sum!=filelength);
|
|
|
|
|
I'm not quite sure what the problem is...
"When I haven't finished uploading a file, downloading it fails part of the way through"
This sounds pretty straightforward to me! A little patience before downloading will probably cure your isssue.
Iain.
|
|
|
|
|
Hi
Thanks for ur response
Im able to start downloading the file using HTTP while the same file is being uploaded using FTP.
When ftp server permits to access that file while it is uploading, y cant we
download that file.
Actually we are able to download the file upto some extent. After that internetreadfile() is returning 0 bytes. After that its not reading the reamining data. internetreadfile()should wait for the requested amount of data. But its not doing so.
Its a bit urgent task for me. Awaiting for ur reply
|
|
|
|
|
Jyo2007 wrote: When ftp server permits to access that file while it is uploading, y cant we
download that file.
Why would you want to download a file that has not been fully uploaded yet?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Inorder to synchronize file upload and download it is quite obvious that u want to download the file which isnt uploaded completely.
When internet read file returns 0, close the handle to internet file, recall httpopenrequest() and httpsendfile()and then continue reading file from the location where previously the downloading has stopped(using internetsetfilepointer method).
|
|
|
|
|
programmer81 wrote: ...it is quite obvious that u...
No, not me.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Why you dont use of URLDownloadToFile Function.
|
|
|
|
|
Hi
I have to retrieve the registery value through RegQueryValueEx().Before
doing this I am using RegOpenKeyEx() to open the registery.But the return value of RegOpenKeyEx() I am getting is 998 i.e the function is not able to successfully open the windows registery.Although,I have tried to map the error code of getlasterror() with the help of FormatMessage(),the return value of
getlasterror() is 0 i.e. "operation completed successfully".
Here is the code:
PHKEY m_htKey;
const char* lpSubKey = "SOFTWARE\\MyProduct\\N K software\\1.5";
long* lpcbValue = NULL;
DWORD valueType = 0;
DWORD dwBufLen = 0;
const char* valueName = "NKSDir";
long res = RegOpenKeyEx(HKEY_CURRENT_USER ,lpSubKey,0,KEY_ALL_ACCESS,m_htKey);
DWORD dw = GetLastError();
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,0,NULL);
//Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
if (res != ERROR_SUCCESS)
return TRUE;
else
{
printf("hi");
res = RegQueryValueEx((HKEY)m_htKey,valueName,NULL,&valueType,NULL,&dwBufLen);
}
Now in the above code, the if condition is getting true and it's returning true.The control is not going into the else condition.
Can you please suggest me what could be the reason behind it that RegOpenKeyEx() is returning non zero value?
With Regards
Neeraj Sinha
|
|
|
|
|
I don't know the solution to your problem (I never worked with the registry) but shouldn't you pass the return value of RegOpenKeyEx to your FormatMessage function instead of GetLastError ? Even if you get an error in RegOpenKeyEx, GetLastError will still return 0.
|
|
|
|
|
Yes I agree.Thanks for your help to remove my confusion.Now I am
getting the correct message of error code 998 through FormatMessage, i.e."Invalid access to memory location".
Can anybody please solve this problem?What could be the possible
reason behind this message?
With Regards
Neeraj Sinha
|
|
|
|
|
Hi,
Cedric's comment is correct, you need to pass the value returned from RegQueryValueEx() to FormatMessage() and then tell us the error you are getting before we can help.
|
|
|
|
|
LONG regResult = ERROR_SUCCESS;
HKEY hKey;
regResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\MyProduct\\N K software\\1.5"
,0,KEY_ALL_ACCESS,&hKey);
if(regResult == ERROR_SUCCESS)
{
unsigned long type=REG_SZ, size=1024;
char res[1024]="";
char res2[1024]="";
long err=RegQueryValueEx(hKey,"Reference",NULL,&type,(LPBYTE)&res[0],&size);
RegCloseKey(hKey);
if(err==ERROR_SUCCESS)
{
//....do necessary code here }
else
//...do code here
}
Hope this will help you!!!!!!!!!!1
|
|
|
|
|
Hi Cedric,Jonathan and D.Mani
Thanks a lot for your quick replies.
I got my problem completely solved now.
With Regards
Neeraj Sinha
|
|
|
|
|
|
My project has a dialog, in this dialog, have two control: A and B
when this dialog print, A covered B, but when B has some change(change color, for example), and then B covered A.
How to lead A covered B again? Thanks!
|
|
|
|
|
Look up SetWindowPos(),you should be able to use this to change your controls Z-order.
|
|
|
|
|
if that's normal for your design that they overlap, then you should hide the control overlapped by calling ShowWindow(FALSE) on it.
otherwise, you have a design issue in your dialog :p
|
|
|
|
|
I set a Dialog's "Vertical scroll" property true.Now I want to calculate its scroll bar's width. how to do it ?
Thanks in advance.
|
|
|
|
|
Peter, Chan wrote: I set a Dialog's "Vertical scroll" property true.Now I want to calculate its scroll bar's width. how to do it ?
::GetSystemMetrics( SM_CXVSCROLL );
|
|
|
|
|
|
|
Hi all,
I was wodering if it is possible to pass values to a thread function without calling _beginthread() for a second time. For example, a thread is created and the thread performs it's tasks, now the thread must perform the same task but this other data, and one doesn't want to create a new thread again. Is this possible ???
Many Thanks
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Yes: there are several ways to do that. In general, what I do is a thread that simply calls a member function of a class to do some processing. The class is passed as an argument to the thread function.
So, as the function is a member of the class, you have access to all the members of the class and you can modify them. Of course, you need to secure this with synchronization objects (critical sections, mutexes, ...) to avoid that a same 'member' is accessed at the same time by two different threads.
I hope it makes sense.
|
|
|
|
|
Thanks Cedric, yes it makes sense, kinda. If I may be so bold as to ask for an example if it is possible.
Many Thanks
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: If I may be so bold as to ask for an example if it is possible.
Something like this:
class CThread
{
public:
CThread();
virtual ~CThread();
void StartThread();
void ThreadFunc();
HANDLE m_hThread;
};
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
CThread* pThread = (CThread*)lpParam;
if (pThread)
pThread->ThreadFunc();
return 0;
}
CThread::CThread()
{
}
CThread::~CThread()
{
}
void CThread::StartThread()
{
m_hThread = CreateThread(NULL,0,ThreadProc,this,0,NULL);
}
void CThread::ThreadFunc()
{
}
|
|
|
|
|