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());

 

posted on 2019-02-19 09:15  空明流光  阅读(765)  评论(0编辑  收藏  举报

导航