Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2004

Tip: Looking for answers? Try searching our database.

cURL stumper (libcurl.dll)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Al Kim - 25 Feb 2004 00:23 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.