在控制台中使用如下代码:        [DllImport("Kernel32.dll", SetLastError = true)]
        public static extern bool SetLocalTime(ref SystemTime sysTime);代码正常调用在Windows service 中使用出错。
parameter type 'ref TimeProtectService.Service1.SystemTime' is less accessible 
than method 'TimeProtectService.Service1.SetLocalTime(ref TimeProtectService.Service1.SystemTime)'在网上查了一下说,Windows service 中大部分API都与控制台或WINFORM 不同。我想问,怎么能够正确调用该方法? 或 有什么方法可以代替如上方法?(方法主要是用来修改系统时间的。)

解决方案 »

  1.   

    谢谢楼上的。就是不想做成WINFORM程序,不然也不会有这个问题了。就是想开机后启动服务进行的。
      

  2.   


    把public 改成private呢
    [DllImport("Kernel32.dll", SetLastError = true)]
      public private static extern bool SetLocalTime(ref SystemTime sysTime);
      

  3.   

    参数中的SystemTime 在哪里定义的?如果你在web service里重新定义了 是用下面的方式么[StructLayoutAttribute(LayoutKind.Sequential)]
    public struct SystemTime
    {
    public short year;
    public short month;
    public short dayOfWeek;
    public short day;
    public short hour;
    public short minute;
    public short second;
    public short milliseconds;
    }
      

  4.   


    你仔细看下错误信息 就会知道了,他说参数类型SystemTime的可见性比方法SetLocalTime的可见性要低
    说明你自己重新定义了SystemTime结构 并且可见性为private,这样当外部调用方法SetLocalTime时无法给第一个参数赋值,因为其为private的,对外不可见Error Message 
    Inconsistent accessibility: parameter type 'type' is less accessible than method 'method'
    The return type and each of the types referenced in the formal parameter list of a method must be at least as accessible as the method itself. Make sure the types used in method signatures are not accidentally private due to the omission of the public modifier. For more information, see Access Modifiers (C# Programming Guide).