Question

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?

Was it helpful?

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.

OTHER TIPS

I know it's old, but for those looking we solved it by:

fz_pixmap_samples wasn't actually exposed (exported) in the 1.8 version of the .so files we were using. If you run nm on it, you'll see it isn't exported. That's why there is the runtime error when trying to use it.

So we had to go to the muPDF website, get the project and source, and make a change and recompile it. I know, it's a pain. Seemed to be the only answer.

Had to go to muPDF.c inside the source/platform/android/jni folder, and in there call fz_pixmap_samples(NULL, NULL) inside one of the methods that has the jni export call. Just calling fz_pixmap_samples(NULL, NULL) in there will now expose it in the .so file when you recompile it.

To recompile muPDF, follow the instructions that are provided in the mupdf project for recompiling for android. They are good instructions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top