gsemac / Gsemac.Common

A collection of .NET utilities for use across my projects
MIT License
7 stars 3 forks source link

Curl callback delegates have the wrong calling conventions #12

Closed LeadAssimilator closed 8 months ago

LeadAssimilator commented 8 months ago

The default delegate calling convention is stdcall on x86, but the bundled version of curl was compiled to expect cdecl callbacks. As a result simple usage of CurlHttpWebRequest throws AVs in 32-bit.

Adding [UnmanagedFunctionPointer(CallingConvention.Cdecl)] to each callback delegate fixes it.


    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate UIntPtr ReadFunctionCallback(IntPtr buffer, UIntPtr size, UIntPtr nItems, IntPtr userData);

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate UIntPtr WriteFunctionCallback(IntPtr data, UIntPtr size, UIntPtr nMemb, IntPtr userData);

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate int ProgressFunctionCallback(IntPtr clientP, double dlTotal, double dlNow, double ulTotal, double ulNow);```
gsemac commented 8 months ago

I hadn't tested it in a 32-bit environment, so I wasn't aware of this problem.

Thank you for bringing this to my attention!