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

How to convert from c++ function pointer to c# delegate? #2888

Open
zmoth opened this issue Apr 23, 2024 · 0 comments
Open

How to convert from c++ function pointer to c# delegate? #2888

zmoth opened this issue Apr 23, 2024 · 0 comments

Comments

@zmoth
Copy link

zmoth commented Apr 23, 2024

SWIG : 4.2.1

Now I have a c++ header file Logger.h.

class Logger
{
  public:
    using LogMessage = void (*)(Logger::Level, const char *);
    static inline void logger_handler(LogMessage h) { Logger::instance()->_handler = h; }
}

Expect c# generate file Logger.cs

public class Logger : global::System.IDisposable {

  ...

  public delegate void LogMessage(Logger.Level level, string message);

  public static void LoggerHandler(LogMessage h) {
    csLoggerPINVOKE.Logger_LoggerHandler(h);
  }

  ...

}

I tried a lot of methods to generate delegate code without success, and I wasn't very familiar with swig and c#. Expect a simple solution. thank you.

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