【问题标题】:Coredll not found error in Windows 10 mobile enterprise application在 Windows 10 移动企业应用程序中找不到 Coredll 错误
【发布时间】:2018-06-22 08:23:55
【问题描述】:

我们正在开发一个可在 Windows 10 移动企业版中运行的移动应用程序。现在需要将系统时间更改为特定值。我们尝试了以下

[DllImport("coredll.dll", SetLastError = true)]
    public static extern bool SetSystemTime(ref SYSTEMTIME st);



[StructLayout(LayoutKind.Sequential)]
            public struct SYSTEMTIME
            {
                public short wYear;
                public short wMonth;
                public short wDayOfWeek;
                public short wDay;
                public short wHour;
                public short wMinute;
                public short wSecond;
                public short wMilliseconds;
            }
      SYSTEMTIME st = new SYSTEMTIME();
            st.wYear = 2018; // must be short
            st.wMonth = 6;
            st.wDay = 21;
            st.wHour = 0;
            st.wMinute = 0;
            st.wSecond = 0;
 SetSystemTime(ref st);

但它会抛出 coredll is not found。我们使用 uwp 和 C# 作为语言。

【问题讨论】:

    标签: c# uwp dllimport


    【解决方案1】:

    您无法在 UWP 应用中设置系统时间,并且 DateTimeSettings API 仅在 IoT 设备中可用。我发现你想导入coredll.dll 静态方法。不幸的是,它在 UWP 中不可用。在 UWP 应用程序中设置系统时间,有很多迂回的方法。例如,您可以启动系统日期setting 页面然后设置时间。

    var uriDateSetting = new Uri(@"ms-settings:dateandtime");
    
    // Set the option to show a warning
    var promptOptions = new Windows.System.LauncherOptions();
    promptOptions.TreatAsUntrusted = true;
    
    // Launch the URI
    var success = await Windows.System.Launcher.LaunchUriAsync(uriDateSetting, promptOptions);
    

    【讨论】:

      【解决方案2】:

      在 UWP 应用中使用 DllImport 调用 Win32 API 是一种 hack。

      我找到了this stackoverflow answerthis blog post

      首先,您只能调用一组选定的 API。 SetSystemTime 不在 list 中。设置系统时间是一个受限权限,我的猜测是系统没有给应用授予这样的权限。

      其次,根据链接的答案,DllImport API 的签名是从api-ms-win-core-sysinfo-l1-2-0.dll 之类的东西导入的,很奇怪,对吧?

      【讨论】:

      • 但是 windows CE 支持这个 coredll。
      • 我不知道,但是距离Win CE最新版本已经5年了,它不是Windows 10 Mobile。您最好尝试从“api-ms-win-core-sysinfo-l1-2-0.dll”导入它,因为它是 GetSystemTime 所在的位置。
      • 谢谢,@kennyzx。但是这个 dll 不适用于 SetSystemTime。
      猜你喜欢
      • 2018-05-11
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      相关资源
      最近更新 更多