/// <summary> /// 初始化非托管委托指针(函数指针); /// </summary> private void InitializePtr() { //位置委托; SetInt64Delegate setPos = OnSetPos; GetInt64Delegate getPos = OnGetPos; delegates.Add(setPos); delegates.Add(getPos); SetPositionFunc( StreamPtr, getPos, setPos ); //长度委托; GetInt64Delegate getLength = OnGetLength; delegates.Add(getLength); SetGetLengthFunc(StreamPtr, getLength); //可读/写委托; GetBoolDelegate canRead = OnCanRead; GetBoolDelegate canWrite = OnCanWrite; delegates.Add(canRead); delegates.Add(canWrite); SetCanReadFunc(StreamPtr, canRead); SetCanWriteFunc(StreamPtr, canWrite); //写入委托; WriteDelegate write = OnWrite; delegates.Add(write); SetWriteFunc(StreamPtr, write); //读取委托; ReadDelegate read = OnRead; delegates.Add(read); SetReadFunc(StreamPtr, read); }
private static extern void SetPositionFunc(IntPtr stream, [MarshalAs(UnmanagedType.FunctionPtr)] GetInt64Delegate getPositionFunc, [MarshalAs(UnmanagedType.FunctionPtr)] SetInt64Delegate setPositionFunc);
private static extern void SetGetLengthFunc(IntPtr stream, [MarshalAs(UnmanagedType.FunctionPtr)] GetInt64Delegate getLengthFunc);