class MarshalTest : ICustomMarshaler
public void CleanUpManagedData(object ManagedObj)
throw new NotImplementedException();
public void CleanUpNativeData(IntPtr pNativeData)
throw new NotImplementedException();
public int GetNativeDataSize()
return 8;
public IntPtr MarshalManagedToNative(object ManagedObj)
throw new NotImplementedException();
public object MarshalNativeToManaged(IntPtr pNativeData)
long UnixTime = 0;
UnixTime = Marshal.ReadInt64(pNativeData);
catch (Exception e)
QFXLogger.Error(e, "MarshalNativeToManaged");
DateTime DT = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DT = DT.AddSeconds(UnixTime);
return DT;
}
以下是类的定义:
代码语言:
javascript
复制
unsafe public struct MT5ServerAttributes
/// <summary>
/// Last known server time.
/// </summary>
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalTest))]
public DateTime CurrentTime;
//[MarshalAs(UnmanagedType.U8)]
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MarshalTest))]
public DateTime TradeTime;
}