Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Please add a switch to indicate whether to generate function pointer declarations. #1016

Open
ssrlive opened this issue Oct 22, 2024 · 0 comments

Comments

@ssrlive
Copy link

ssrlive commented Oct 22, 2024

Please add a switch to indicate whether to generate function pointer declarations.

If you think it is optional, you can add a switch to indicate whether to generate it.

Now, only function declarations of the form

int foo(int a, int b);

can be generated from the cbindgen tool, but no function pointer declarations of the form

int (*pfn_foo)(int a, int b);

can be generated.

This makes it very inconvenient when we dynamically load the dll library generated by rust.

I hope you will consider this request.

For example,

#include <windows.h>
#include <stdio.h>

// define a function pointer type by ourselves
typedef int (*pfn_foo)(int, int);

int main() {
    HMODULE hModule = LoadLibrary("a.dll");
    if (hModule == NULL) {
        return 1;
    }

    pfn_foo foo = (pfn_foo)GetProcAddress(hModule, "foo");
    if (foo == NULL) {
        FreeLibrary(hModule);
        return 1;
    }

    int result = foo(5, 10);
    printf("result: %d\n", result);

    FreeLibrary(hModule);
    return 0;
}
@ssrlive ssrlive changed the title Please add a switch to indicate whether to generate function pointer declarations. [Feature Request] Please add a switch to indicate whether to generate function pointer declarations. Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant