cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: bitmap buffer (c++)

From: Luiz Rafael Culik Guimaraes <luiz_at_xharbour.com.br>
Date: Thu, 13 Nov 2008 13:36:37 -0200

Hi
I dont know if is related, but on my c++ code when i need to pass an
structure to CURLOPT_WRITEDATA i do this way

// using your code as base
typedef struct MemoryStruct {
unsigned char *memory;
size_t size;
} MEMORYSTRUCT,*PMEMORYSTRUCT;

size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
register int realsize = size * nmemb;
PMEMORYSTRUCT mem = (PMEMORYSTRUCT )data;
mem->memory = (unsigned char *)realloc(mem->memory, mem->size + realsize +
1);
if (mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}
return realsize;
}

void conta() throw (std::runtime_error){
...
...
...
CURL *curl_handle;
while(true){
char* info;
PMEMORYSTRUCT chunk = malloc( sizeof( struct MemoryStruct ));
chunk->memory=NULL;
chunk->size = 0;
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL,
"http:/111.111.11.11/axis-cgi/bmp/image.bmp");
        curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
WriteMemoryCallback);
                curl_easy_setopt(curl_handle, CURLOPT_HEADER,false);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)chunk);
CURLcode error;
error=curl_easy_perform(curl_handle);

//Here i use the buffer stored in the chunk
                free( chunk);
                curl_easy_cleanup(curl_handle);

...
...
... }

}

perhaps this help,

Regards
Luiz
Received on 2008-11-13