Jump to content

Libcurl.dll Trouble with WRITEFUNCTION

Recommended Posts



I'm trying to use the easy interface of libcurl.dll.

In thirst, i'm doing that



Share this post

Link to post
Share on other sites


I'm trying to use the easy interface of libcurl.dll.

In first,

I call curl_easy_init

i call curl_easy_setopt for the url

i call curl_easy_perform

i call curl_easy_cleanup

It gave me the source code, but in the output. I don't want that. So after research, i found the setopt CURLOPT_WRITEFUNCTON.

So i have write this :

; #GLOBALES# ====================================================================================================================
Global Const $hDll = DllOpen(@ScriptDir & "\libcurl.dll")
Global Const $CURLOPT_URL = 10002
Global Const $CURLOPT_VERBOSE = 41
Global Const $CURLOPT_NOPROGESS = 43
Global Const $sUrl = "http://www.google.com"
Global $response_data = ""
; ===============================================================================================================================

ConsoleWrite("[DEBUG] DllOpen : " & $hDll & @CRLF)

Local $aHandleEasy = DllCall($hDll, "ptr:cdecl", "curl_easy_init")
ConsoleWrite("[DEBUG] curl_easy_init : " & @error & @CRLF)

Local $tCURLSTRUCT_URL = DllStructCreate("char[" & StringLen($sUrl) + 1 & "]")
DllStructSetData($tCURLSTRUCT_URL, 1, $sUrl)
Local $aRes = DllCall($hDll, "int:cdecl", "curl_easy_setopt", "ptr", $aHandleEasy[0], "int", $CURLOPT_URL, "long", DllStructGetPtr($tCURLSTRUCT_URL))
ConsoleWrite("[DEBUG] curl_easy_setopt : " & $aRes[0] & " " & @error & @CRLF)

$Write_Data = DllCallbackRegister("_Write_Data", "uint", "ptr;uint;uint;ptr")
ConsoleWrite("[DEBUG] Pointer of DllCallback WriteFonction : " & DllCallbackGetPtr($Write_Data) & @CRLF)
Local $aRes = DllCall($hDll, "int:cdecl", "curl_easy_setopt", "ptr", $aHandleEasy[0], "int", $CURLOPT_WRITEFUNCTION, "ptr", DllCallbackGetPtr($Write_Data))
ConsoleWrite("[DEBUG] curl_easy_setopt : " & $aRes[0] & " " & @error & @CRLF)

Local $aRes = DllCall($hDll, "int:cdecl", "curl_easy_perform", "ptr", $aHandleEasy[0])
ConsoleWrite("[DEBUG] curl_easy_perform : " & $aRes[0] & " " & @error & @CRLF)

DllCall($hDll, "none:cdecl", "curl_easy_cleanup", "ptr", $aHandleEasy[0])
If @error Then ConsoleWrite("[DEBUG] Failed curl_easy_cleanup" & @CRLF)


Func _Write_Data($ptr,$nSize,$nMemb,$pStream)

   ConsoleWrite("11" & @CRLF)
   Return $nSize*$nMemb


Giving a ptr of a calback for the CURLOPT_WRITEFUNCTION. Yes, there is nothing in my callback function, but this is not a problem. I think.

When i exec that, it give me this output :

[DEBUG] DllOpen : 1
[DEBUG] curl_easy_init : 0
[DEBUG] curl_easy_setopt : 0 0
[DEBUG] Pointer of DllCallback WriteFonction : 0x006D0000
[DEBUG] curl_easy_setopt : 0 0

My DllOpen don't return -1, it's fine, all of my opt return 0, it's fine. I see my callback, it's the 11. But the script block in the curl_easy_perform.

I don't know why ... I'm doing something wrong, but what ? And why ?

After ~30s curl_easy_perform crash, my script crash and don't display the line :


ConsoleWrite("[DEBUG] curl_easy_perform : " & $aRes[0] & " " & @error & @CRLF)

Thanks for your help.


ps: My script require : libcurl.dll libssl-1_1.dll libcrypto-1_1.dll

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.