Try another definition:
[DllImport("kernel32.dll")]
private static extern bool SetSystemTimeAdjustment( UInt32 TimeAdj, bool AdjDisable);
And adjust the code.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to override w32tm to adjust the DateTime clock-rate in C#. When I call the kernel32 API:
SetSystemTimeAdjustment(ref dwTimeAdjustment, ref bTimeAdjustmentDisabled);
I get a return of true, indicating it worked, but when I read back the results with GetSystemTimeAdjustment, lpTimeIncrement = lpTimeAdjustment, and the lpTimeAdjustmentDisabled is true, when I passed false in, indicating the Set operation disabled the clock adjust, rather than changing the rate.
The function call looks like this:
WinRTClk.SetClockRate(156123); // Test to see if the clock can be sped up.
Here is the class:
public static class WinRTClk
{
public static UInt32 ClkInterval = 0;
public static UInt32 ClkRate = 0;
private static bool ClkAdjDisable = false;
public static double RTC_Adj_Ratio()
{
GetClockRate();
return ((double) ((Int64) ClkRate - ClkInterval)) / ClkInterval;
}
public static bool GetClockRate() { return GetSystemTimeAdjustment(ref ClkRate, ref ClkInterval, ref ClkAdjDisable); }
public static bool SetClockRate(Int32 Offset)
{
GetClockRate(); // Update ClkInterval
UInt32 NewRate = (UInt32) ((Int64) ClkInterval + Offset);
bool Disable = false;
return SetSystemTimeAdjustment(ref NewRate, ref Disable);
}
// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimeadjustment
[DllImport("kernel32.dll")]
private static extern bool GetSystemTimeAdjustment(ref UInt32 TimeAdj, ref UInt32 ClkInc, ref bool AdjDisable);
//https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-setsystemtimeadjustment
[DllImport("kernel32.dll")]
private static extern bool SetSystemTimeAdjustment(ref UInt32 TimeAdj, ref bool AdjDisable);
}
Try another definition:
[DllImport("kernel32.dll")]
private static extern bool SetSystemTimeAdjustment( UInt32 TimeAdj, bool AdjDisable);
And adjust the code.