0

我正在尝试在 Mono for Android 应用程序中在 Android 上呈现 PDF 文档。我正在使用用 C 编写的 MuPdf 库,并且在调用一个 C 函数时遇到问题。我得到什么:

System.EntryPointNotFoundException: fz_pixmap_samples

C函数:

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

我的 C# 包装器:

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);
    }
}

我调用 GetSamples 的方式:

APV.GetSamples(context, pix);

函数 fz_pixmap_samples(fz_context *ctx, fz_pixmap *pix) 应该返回指向位图数据的指针。我假设将 unsigned char * 映射到 IntPtr 不正确?有人可以帮忙吗?

4

2 回答 2

0

System.EntryPointNotFoundException:fz_pixmap_samples

表示该库不导出名为fz_pixmap_samples. 很可能存在一些名称修饰,这意味着该函数以不同的名称导出。

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.

于 2013-03-29T17:05:23.223 回答
0

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.

于 2016-06-03T20:05:41.860 回答