cURL / Mailing Lists / curl-library / Single Mail


(CURLOPT_WRITEFUNCTION + curl_formadd) problem on MSVS 2005

From: Anthony K <>
Date: Wed, 14 May 2008 00:20:03 +0700


I have problem with libcurl, at win32 system with curl_formadd and CURLOPT_WRITEFUNCTION.

It's modified C code example.
If curl_formadd functions not commented "mycallback" function doesn't executes.
I got this problem on win32 system with MSVS 2005, on Linux/FreeBSD with GCC this code works without any problems.

Thnx for help!


#include <stdio.h>
#include <string.h>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

size_t mycallback(void * buffer, size_t n, size_t m, void * stream)
        char * l = (char*)buffer;
        printf("data: %s \n", l);
        return n;

int main(int argc, char *argv[])
  CURL *curl;
  CURLcode res;

  struct curl_httppost *formpost=NULL;
  struct curl_httppost *lastptr=NULL;
  struct curl_slist *headerlist=NULL;
  char buf[] = "Expect:";

  //curl = curl_easy_init();

               CURLFORM_COPYNAME, "sendfile",
               CURLFORM_FILE, "postit2.c",

               CURLFORM_COPYNAME, "filename",
               CURLFORM_COPYCONTENTS, "postit2.c",

               CURLFORM_COPYNAME, "submit",
               CURLFORM_COPYCONTENTS, "send",

  curl = curl_easy_init();
  /* initalize custom header list (stating that Expect: 100-continue is not
     wanted */
  headerlist = curl_slist_append(headerlist, buf);
  if(curl) {
    /* what URL that receives this POST */
    curl_easy_setopt(curl, CURLOPT_URL, "");
    if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )
      /* only disable 100-continue header if explicitly requested */
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mycallback);
    res = curl_easy_perform(curl);

    /* always cleanup */

    /* then cleanup the formpost chain */
    /* free slist */
    curl_slist_free_all (headerlist);
  return 0;
Received on 2008-05-13