DLL中導出的函數
typedef void (*HQ_MSG_CALLBACK)(void *h, int nMsg, int nMsgType, int nReqNo, const char *szData, int nSize);
void SetMsgFunc(void *h, HQ_MSG_CALLBACK pmsgCallBack);
C#動態調用上述函數
public delegate void CALLBACK(IntPtr h, int nMsg, int nMsgType, int nReqNo, IntPtr data, int nSize);
[DllImport(DllPath, CallingConvention = CallingConvention.Cdecl)]
private static extern void SetMsgFunc(CALLBACK pmsgCallBack);public static void HQCallBack(IntPtr h, int nMsg, int nMsgType, int nReqNo, IntPtr data, int nSize)
{}
HQ_MSG_CALLBACK callBackFunc = new HQ_MSG_CALLBACK(HQCallBack);
SetMsgFunc(callBackFunc);//也可直接傳HQCallBack函數名
其中函數指針由委托delegate替代,使用時可以傳委托對象,也可以直接傳函數名;指針由IntPtr替代