好的,这是有效的:
[StructLayout(LayoutKind.Explicit,Size = 28)] public unsafe struct HandleProxy { [FieldOffset(0),MarshalAs(UnmanagedType.I4)] public JSValueType _ValueType; // JSValueType is an enum [FieldOffset(4),MarshalAs(UnmanagedType.I4)] public Int32 _ManagedObjectID; [FieldOffset(8)] public void* _NativeEngineProxy; [FieldOffset(16),MarshalAs(UnmanagedType.I4)] public Int32 _EngineID; [FieldOffset(20)] public void* _Handle; } [DllImport("Proxy")] public static extern void DisposeHandleProxy(HandleProxy* handle);
……这不……
[StructLayout(LayoutKind.Explicit,Size = 20)] public unsafe struct ValueProxy { [FieldOffset(0),MarshalAs(UnmanagedType.I4)] public JSValueType _ValueType; // 32-bit type value. [FieldOffset(4),MarshalAs(UnmanagedType.Bool)] public bool _Boolean; [FieldOffset(4),MarshalAs(UnmanagedType.I4)] public Int32 _Integer; [FieldOffset(4)] public double _Number; [FieldOffset(12)] public void* _String; } [DllImport("Proxy")] public static extern void DisposeValueProxy(ValueProxy* valueProxy);
那么,有什么区别?我错过了什么.调用“DisposeValueProxy()”会出现以下错误:
“无法封送’参数#1’:指针不能引用封送结构.请改用ByRef.”
(是的,我可以简单地使用IntPtr / void *代替“ValueProxy *”但这不是我的观点).
对“DisposeHandleProxy()”的调用工作正常.
让我们看看是否有人可以解决这个问题. 原文链接:https://www.f2er.com/csharp/238964.html