Search code examples
xamarin.androidpinvokemupdf

Mono for Android and MuPdf PInvoke


I'm trying to render PDF document on Android within Mono for Android application. I'm using MuPdf library wiritten in C and have problem with invoking one C function. What I get:

System.EntryPointNotFoundException: fz_pixmap_samples

C function:

unsigned char *fz_pixmap_samples(fz_context *ctx, fz_pixmap *pix)
{
    if (!pix)
        return NULL;
    return pix->samples;
}

My C# wrapper:

public class APV
{
    [DllImport("libmupdf.so", EntryPoint = "fz_pixmap_samples", CallingConvention = CallingConvention.Cdecl)]
    private static extern IntPtr fz_pixmap_samples(IntPtr ctx, IntPtr pix);

    public static IntPtr GetSamples(IntPtr ctx, IntPtr pix)
    {
        return fz_pixmap_samples(ctx, pix);
    }
}

the way I'm calling GetSamples:

APV.GetSamples(context, pix);

Function fz_pixmap_samples(fz_context *ctx, fz_pixmap *pix) should return me pointer to bitmap data. I'm assuming mapping unsigned char * to IntPtr is not correct? Could anyone help?


Solution

  • System.EntryPointNotFoundException: fz_pixmap_samples

    means that the library does not export a function named fz_pixmap_samples. Most likely there is some name decoration that means that the function is exported with a different name.

    The first thing to do is to remove the EntryPoint argument which will allow the managed code to look for decorated names.

    If that doesn't get it done then you need to study the .so library file to find out exactly what name is used to export the function. And use that in your p/invoke declaration.