Home > Net >  How the CLR packaging c to c # call, entrust to c function pointer
How the CLR packaging c to c # call, entrust to c function pointer

Time:09-21

Using the CLR packaging SDK to use c #, c + + callback is a function pointer in the SDK, want to pass the CLR packaging, using c # delegate
 
//core. H
The namespace Core {
Public ref class Live
{
Public:
The delegate void SucDelegateCallBack (void * data);
Void init (SucDelegateCallBack ^ suc);
};
}

 
//core. CPP
The namespace Core {
Void Live: : init (SucDelegateCallBack ^ suc) {
//SDK header files relevant content:
//typedef void SucCallback (*) (void * data);
//virtual void init (SucCallback suc=NULL)=0.

//want to implement the following ideas, but don't know how to transfer suc SucCallback
GetCore () - & gt; Init (SucDelegateCallBack);//this is false: wrong parameter type
}
}


How to SucDelegateCallBack into SucCallback?

CodePudding user response:

Has been solved!

IntPtr IP=Marshal: : GetFunctionPointerForDelegate (suc);
SucCallback cb=static_cast & lt; SucCallback> (IP) ToPointer ());

CodePudding user response:

Thank you, learn a simple call the delegate
  •  Tags:  
  • C#
  • Related