且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#如何将IntPtr转换为结构?

更新时间:2023-02-07 22:16:47

您应该调用PtrToStructure的重载,该重载期望使用类型而不是对象。正是导致错误的原因:

You should call the overload of PtrToStructure that expects a type instead of an object. That's what's causing the error probably:

var ver = Marshal.PtrToStructure(ptr, typeof(MathServLib.sVersionStruct));