JosePineiro / WebP-wrapper

Wrapper for libwebp in C#. The most complete wapper in pure managed C#. Exposes Simple Decoding API, Simple Encoding API, Advanced Encoding API (with stadistis of compresion), Get version library and WebPGetFeatures (info of any WebP file). In the future I´ll update for expose Advanced Decoding API. The wapper are in safe managed code in one class. No need external dll except libwebp.dll (included). The wapper work in 32 and 64 bit system.
MIT License
214 stars 48 forks source link

Question for using in ASP.NET Web Application #33

Closed DiracSpace closed 2 years ago

DiracSpace commented 2 years ago

I have an ASP.NET application using .NET Core 3.1 and I'm wondering where I should put the .dll files. There is a bin/Release folder in Project.WebApi so, should I add them there?

DiracSpace commented 2 years ago

The previous question works but I'm getting this issue and can't seem to pinpoint the problem. Message: "Unable to find an entry point named 'CopyMemory' in DLL 'kernel32.dll'.\r\nIn WebP.AdvancedEncode"

It seems to arrive to this part of the code in the wrapper:

// not working
//compress the input samples
if (UnsafeNativeMethods.WebPEncode(ref config, ref wpic) != 1)
    throw new Exception("Encoding error: " + ((WebPEncodingError)wpic.error_code).ToString());

That jumps to this code here and it breaks upon entering WebPEncode_x64

/// <summary>Compress to WebP format</summary>
/// <param name="config">The configuration structure for compression parameters</param>
/// <param name="picture">'picture' hold the source samples in both YUV(A) or ARGB input</param>
/// <returns>Returns 0 in case of error, 1 otherwise. In case of error, picture->error_code is updated accordingly.</returns>
internal static int WebPEncode(ref WebPConfig config, ref WebPPicture picture)
{
    switch (IntPtr.Size)
    {
        case 4:
            return WebPEncode_x86(ref config, ref picture);
        case 8:
            return WebPEncode_x64(ref config, ref picture);
        default:
            throw new InvalidOperationException("Invalid platform. Can not find proper function");
    }
}
[DllImport("libwebp_x86.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPEncode")]
private static extern int WebPEncode_x86(ref WebPConfig config, ref WebPPicture picture);
[DllImport("libwebp_x64.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "WebPEncode")]
DiracSpace commented 2 years ago

The solution is to change:

[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]

You should end up with:

[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false, ExactSpelling = true)]
internal static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);