cURL / Mailing Lists / curl-library / Single Mail

curl-library

Libcurl, WinApi and progress bar

From: Borucik <borucik_at_gmail.com>
Date: Thu, 22 Feb 2007 13:15:16 +0100

Is it possible to have a progress bar in WinApi while downloading file via
HTTP protocol?
I used the easy interface with these options:

curl_easy_setopt(context, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(context, CURLOPT_PROGRESSFUNCTION,
&file_receiver::show_progress);
curl_easy_setopt(context, CURLOPT_PROGRESSDATA, IDC_PROGRESS1);

IDC_PROGRESS1 is a part of a dialog box, a progress bar created by the
editor.

My function show_progress is a member of a file_receiver class, it looks
like this:

int file_receiver::show_progress(UINT ID_PROGRESS, double dltotal, double
dlnow, double utotal, double ulnow){
    INITCOMMONCONTROLSEX iccInit;
    iccInit.dwSize = sizeof(iccInit);
    iccInit.dwICC = ICC_PROGRESS_CLASS;
    InitCommonControlsEx(&iccInit);
    SendDlgItemMessage((HWND)IDD_DIALOG1, IDC_PROGRESS1, PBM_SETRANGE, 0,
(LPARAM)MAKELONG(0,10));
    SendDlgItemMessage((HWND)IDD_DIALOG1, IDC_PROGRESS1, PBM_SETPOS,
(WPARAM)(dlnow/dltotal*10), 0);
    SendDlgItemMessage((HWND)IDD_DIALOG1, IDC_PROGRESS1, PBM_SETSTEP, 0, 0);
    return 0;
}

The program used to download the file correctly when I was not trying to
come up with the progress bar, but now i gives me the following error and
crashes:

Debug Error!
Program: ...
Module: \Visual Studio 2005\Projects\Libcurl_download\debug\libcurl.dll
Run-time check failure #0 - The value of ESP was no properly saved across
the function call. This is usually result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention.

I use Visual C++ 2005 Express Edition.
Thanks in advance,
Przemek
Received on 2007-02-22