Hi all,
I'm attempting to write a wrapper for the open source cURL program found
at http://curl.haxx.se/ in c-sharp. It's a great program, but
unfortunately no one thus far has tried to write a c# version. Any
takers?
In the meantime, my problem is...
I've made the libcurl.dll (written in C). No problem. I can access
some of the functions, but one is stumping me.
The problematic function is defined as:
CURLcode curl_easy_setopt(CURL *handle, CURLoption option, parameter);
I want to pass a call back option (CURLOPT_WRITEFUNCTION) as a parameter
(http://curl.haxx.se/libcurl/c/curl_easy_setopt.html).
"Function pointer that should match the following prototype:
size_t function( void *ptr, size_t size, size_t nmemb, void *stream);
This function gets called by libcurl as soon as there is data received
that needs to be saved. The size of the data pointed to by ptr is size
multiplied with nmemb, it will not be zero terminated. Return the number
of bytes actually taken care of. If that amount differs from the amount
passed to your function, it'll signal an error to the library and it
will abort the transfer and return CURLE_WRITE_ERROR. "
How do I call the function and point the '*parameter' to another
function? And what would such a function look like?
My c# code so far is:
[DllImport("libcurl.dll")]
public static extern int curl_easy_setopt (IntPtr handle, int option,
int value);
Thanks!
-Allen
Andrew van der Stock - 05 Apr 2004 02:18 GMT
You need to create a delegate of your C# function to pass back to curl. See
MSDN for info regarding function pointers and call backs.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conmarshalingclassesstructuresunions.asp
Why not just make a curl-like C# component using .NET's HTTPWebRequest and
friends? It will be faster.
Andrew
> Hi all,
>
[quoted text clipped - 38 lines]
>
> -Allen
Daniel Stenberg - 05 Apr 2004 14:01 GMT
> Why not just make a curl-like C# component using .NET's HTTPWebRequest and
> friends? It will be faster.
My 2 cents on this:
1. I doubt it will be noticably faster.
2. libcurl offers a lot more options and features than HTTPWebRequest