Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4060412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:20:04+00:00 2026-05-20T15:20:04+00:00

I have written a small util in an app that syncs the time from

  • 0

I have written a small util in an app that syncs the time from a time server, which uses the Windows API functions GetSystemTime and SetSystemTime. It was all working fine, but now every time I call Get/SetSystemTime I get an error:

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.

Now as the only unsafe code is a call to the Win32 functions (is that even unsafe??) it seems it cant be in my code – that and i havent changed anythig since it was actually working…

Any ideas what might be going on here?

The Win32 calls are made using:

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);

EDIT: Now the very same code (unmodified) is giving me an AccessViolation ???

Attempted to read or write protected memory.  
This is often an indication that other memory is corrupt.
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:20:05+00:00Added an answer on May 20, 2026 at 3:20 pm

    Since you are defining SYSTEMTIME as a class, when you pass it by reference you are actually passing a pointer to a pointer but on the unmanaged side it is expecting a pointer to a SYSTEMTIME structure.

    Either change your definition of SYSTEMTIME to a struct and pass it by reference as you are doing now. Or leave it as a class and change your declares to:

    [DllImport("kernel32.dll")]
    static extern void GetSystemTime([Out] SYSTEMTIME systemTime);
    
    [DllImport("kernel32.dll")]
    public extern static uint SetSystemTime([In] SYSTEMTIME systemTime);
    

    Personally, I would change it to a struct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small chat app that uses mysql + php to facilitate
I have written a small app that puts my bluetooth in discoverable mode for
I have written a small function, which uses ElementTree to parse xml file,but it
I have written a small program which uses function pointers to do some numerical
I have written a small System.Windows.Forms.UserControl , call it userControl1 , that seems to
I have written a small .net Windows Forms application. And now I decided to
I have written a small makefile for a few simple C programs that compiles
I have written a small GUI with qtdesigner and python which should display in
I have written a small test program in which I try to use the
I have written a small XML validator, that takes in an XML file and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.