c#函数地址传入c++

c#

private delegate void ValidateEvent(int eventCode);

        private static void ValidateEventCallback(int eventCode)
{
Debug.Print("Validate Event:" + eventCode.ToString());
}

c++

typedef void ( *CPPCallback )(
int eventCode);
STDMETHODIMP CValidator::ValidateEvent(int procAddress)
{
// TODO: 在此添加实现代码 this->validateEventProc = (CPPCallback)procAddress;
return S_OK;
}

传入:

var method = new ValidateEvent(ValidateEventCallback);
var methodAddress = Marshal.GetFunctionPointerForDelegate(method);
securityValidator.ValidateEvent(methodAddress.ToInt32());
上一篇:洛谷P1027 Car的旅行路线


下一篇:洛谷 P1027 Car的旅行路线 最短路+Dijkstra算法