Richard,
Thanks for the fast and helpful reply.
I understood that in theory the library supports third-party DLLs. Since I couldn't find examples I had to guess a little how to tackle this. You confirming that the syntax used in the SYS to register the callback function is therefor valuable.
The library documentation states that the 'easy' interface for it is synchronous so I assume re-entrance isn't a thing then.
With this code:
Code: Select all
SYS "LoadLibrary", @dir$ + "libcurl.dll"
SYS "GetModuleHandle", @dir$ + "libcurl.dll" TO Dll%
IF Dll% == 0 ERROR 100, "Could not load libcurl.dll"
SYS "GetProcAddress", Dll%, "curl_easy_init" TO `curl_easy_init
SYS "GetProcAddress", Dll%, "curl_easy_cleanup" TO `curl_easy_cleanup
SYS "GetProcAddress", Dll%, "curl_easy_perform" TO `curl_easy_perform
SYS "GetProcAddress", Dll%, "curl_easy_setopt" TO `curl_easy_setopt
SYS "GetProcAddress", Dll%, "curl_easy_strerror" TO `curl_easy_strerror
CURLE_OK = 0
CURLOPT_URL = 10002
CURL_WRITEFUNC_ERROR = 23
CURLOPT_WRITEFUNCTION = 20011
INSTALL @lib$ + "CALLBACK"
URL$="http://www.hellomike.nl/"
SYS `curl_easy_init TO Curl
IF Curl THEN
PRINT "CURL initialization done"
SYS `curl_easy_setopt, Curl, CURLOPT_URL, URL$
SYS `curl_easy_setopt, Curl, CURLOPT_WRITEFUNCTION, 0
REMSYS `curl_easy_setopt, Curl, CURLOPT_WRITEFUNCTION, FN_callback(FNwrite_callback(), 4)
SYS `curl_easy_perform, Curl TO Res%
IF Res% <> CURLE_OK THEN
PRINT "curl_easy_perform failed"
SYS `curl_easy_strerror, Res% TO Error%
PRINT $$Error% " (#";Res% ")"
ELSE
PRINT "curl_easy_perform successful"
ENDIF
SYS `curl_easy_cleanup, Curl
ELSE
PRINT "CURL initialization failed"
ENDIF
END
REM ----------------------------------------------------------------------
DEF FNwrite_callback(ptr%, size%, nmemb%, userdata%)=CURL_WRITEFUNC_ERROR
The perform seems to work.
Code: Select all
CURL initialization done
curl_easy_perform successful
But when I remove the REM and run, the interpreter freezes.
Maybe you can detect a flaw.
Instead I can make a little piece of assembly that POPs the 4 dwords from the stack and return in order to see if at least that works.
Thanks
Mike