简体   繁体   中英

DLL Import use SYSTEMTIME

I have a dll developed using C++. Now I wish to use these functions in my C# application. I know how to use the dll in my application, but my problem is that the dll expects a parameter which is of type SYSTEMTIME.

[DllImport("MyControl.dll")]
 public static extern Int32 MyCONTROL_NewControl(SYSTEMTIME stime);

But I am not able to use the SYSTEMTIME in my C# code. Please suggest a workaround on how to use SYSTEMTIME .

That should work:

[StructLayout(LayoutKind.Sequential)]
private struct SYSTEMTIME {
    Int16 wYear;
    Int16 wMonth;
    Int16 wDayOfWeek;
    Int16 wDay;
    Int16 wHour;
    Int16 wMinute;
    Int16 wSecond;
    Int16 wMilliseconds;
}

See also the ready to use solution from pinvoke like Christian.K pointed to.

That's how you use it in c#:

    [StructLayout(LayoutKind.Sequential)]
    public struct SYSTEMTIME
    {
        ushort wYear;//ushort = WORD
        ushort wMonth;
        ushort wDayOfWeek;
        ushort wDay;
        ushort wHour;
        ushort wMinute;
        ushort wSecond;
        ushort wMilliseconds;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM