bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

How to parsing function pointer that has mutidimensional array parameter? #582

Open rodamin opened 2 years ago

rodamin commented 2 years ago
// in header file

int (* testFunc)(char[][256] value);
// in generated java file

public static class TestFunc_BytePointer extends FunctionPointer {
    static { Loader.load(); }
    public TestFunc_BytePointer (Pointer p) { super(p); }
    protected TestFunc_BytePointer () { allocate(); }
    private native void allocate();

    public native int call(@Cast("char*") BytePointer errorList);
}
// generated native jni file

struct JavaCPP_hidden JavaCPP_org_bytedeco_test_ClassName_00024TestFunc_1BytePointer{
JavaCPP_org_bytedeco_test_ClassName_00024TestFunc_1BytePointer() : ptr(NULL), obj(NULL) { }
    int operator()(char* arg0);
    int (*ptr)(char* arg0);
    jobject obj; static jmethodID mid;
};

=> compile error error C2440: '=': cannot convert from 'int (cdecl *)(char [][256])' to 'int (cdecl )(char )'

saudet commented 2 years ago

The Parser is probably going to have a hard time with that. Try to output the definition using Info.javaText: https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#mapping-a-declaration-to-custom-code

rodamin commented 2 years ago

@saudet How to select call method of Function Pointer?

I tried new Info ("ClassName::testFunc") but it doesn't work.

saudet commented 2 years ago

It's probably picking it up as int (*)(char*).

rodamin commented 2 years ago

@saudet Oh, thank you! I'll give it a try!