I have a native class which requires a function pointer in the constructor. I have tried searching the forums, but couldnt quite find what I was looking for.
The native class looks like this:
class NativeClass{
NativeClass(std::string(*callback)(std::string args)){
//native code goes here
}
};
What is the best way of passing a delegate? Any help will be appreciated.
You need to use
Marshal.GetFunctionPointerForDelegate()to achieve this.Note that this will return a function pointer that uses the
stdcallcalling convention. You can specify a different calling convention by using theUnmanagedFunctionPointerattribute on your delegate declaration.