Определение обратного вызова C++
Код: Выделить всё
namespace omk_api
{
enum LogSeverity : int
{
Error = 1,
Warning = 2,
Info = 3,
Trace = 4
};
typedef void(__stdcall* logProc)(const wchar_t* source, const wchar_t* message, LogSeverity severity);
}
Код: Выделить всё
extern "C" __declspec(dllexport) void* __stdcall CreateController(omk_api::logProc log)
{
return (void*)(new omk_controller::Controller(log));
}
Код: Выделить всё
public class Controller : IDisposable
{
private IntPtr instance;
private LogProc logProc;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void LogProc([MarshalAs(UnmanagedType.LPWStr)] string source,
[MarshalAs(UnmanagedType.LPWStr)] string message,
LogSeverity severity);
// (...)
[DllImport("OpenMacroKeyboard.Controller.dll")]
private static extern IntPtr CreateController(LogProc log);
// (...)
private void Log(string source, string message, LogSeverity severity)
{
}
// Public methods -----------------------------------------------------
public Controller()
{
logProc = new LogProc(Log);
instance = CreateController(logProc);
}
// (...)
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... rom-c-to-c