cURL / Mailing Lists / curl-library / Single Mail

curl-library

Callback progress function mess-up upload

From: Dumitru Adrian <dumitru.adryi095_at_yahoo.com>
Date: Mon, 3 Jan 2011 12:01:32 -0800 (PST)

Im trying to make an uploader for a page using winapi and add a progressbar
Upload works only if i disable callback of my progress meter function
If I enabe callback after 1 second message box apper saying that upload was completed but nothing was uploaded
What could be the problem?
Can i get somehow realtime progress with curl_easy_getinfo()?
Here is the upload function

int my_dummy_write(void *ptr, size_t size, size_t nmemb, FILE *s)
{
    return size;
}

int progres(void *clientp,double dltotal,double dlnow,double ultotal,double ulnow)                             
{
    SendMessage(baraprogres,PBM_SETPOS,(WPARAM)((ulnow/ultotal)*100),0);
    return 1;
}

void upload()
{
    OPENFILENAME ofn;      
    char szFile[MAX_PATH];      
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hWnd;
    ofn.lpstrFile = szFile;
    ofn.lpstrFile[0] ='\0';
    ofn.nMaxFile = sizeof(szFile);
    ofn.lpstrFilter = "Toate Fisierele\0*.*\0";
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    if(GetOpenFileName(&ofn))
    {
        CURL *curl;
        CURLcode res;
        struct curl_httppost *formpost=NULL;
        struct curl_httppost *lastptr=NULL;
        curl_global_init(CURL_GLOBAL_ALL);
        curl_formadd(&formpost,&lastptr,CURLFORM_COPYNAME,"filetoupload",CURLFORM_FILE,szFile,CURLFORM_END);
        curl = curl_easy_init();
        if(curl)
        {
            curl_easy_setopt(curl, CURLOPT_URL, "site/upload.php");
            curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
            curl_easy_setopt(curl,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10 (V1)");
            curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
            curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION,&progres);   
            curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, &my_dummy_write);
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
            curl_formfree(formpost);
            MessageBox(hWnd,"fisier incarcat","info",MB_OK);
        }
    }
}

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-01-03