Windows API 関数GetSystemTime
とSetSystemTime
. すべて正常に機能していましたが、今では呼び出すたびにGet/SetSystemTime
エラーが発生します。
FatalExecutionEngineError was detected Message: The runtime has encountered a fatal error. The address of the error was at 0x792bee10, on thread 0x48c. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
現在、唯一の安全でないコードは Win32 関数の呼び出しです (それは安全ではないのでしょうか??) 私のコードにはないようです - それは実際に動作していたので何も変更していません...
ここで何が起こっているのでしょうか?
Win32 呼び出しは、次を使用して行われます。
public class SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Millisecond;
public static implicit operator SystemTime(DateTime dt)
{
SystemTime rval = new SystemTime();
rval.Year = (ushort)dt.Year;
rval.Month = (ushort)dt.Month;
rval.Day = (ushort)dt.Day;
rval.DayOfWeek = (ushort)dt.DayOfWeek;
rval.Hour = (ushort)dt.Hour;
rval.Minute = (ushort)dt.Minute;
rval.Second = (ushort)dt.Second;
rval.Millisecond = (ushort)dt.Millisecond;
return rval;
}
public static implicit operator DateTime(SystemTime st)
{
return new DateTime(st.Year, st.Month, st.Day, st.Hour, st.Minute, st.Second, st.Millisecond);
}
};
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime")]
public extern static void Win32GetSystemTime(ref SystemTime sysTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime")]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);
編集:今、まったく同じコード(変更されていない)がAccessViolationを与えています???
Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.