示例#1
0
        public static bool QueryServiceConfig2 <T>(IntPtr hService, ServiceConfigOption dwInfoLevel, out T configInfo)
        {
            var b = QueryServiceConfig2(hService, dwInfoLevel, IntPtr.Zero, 0, out uint size);

            configInfo = default(T);
            if (!b && Win32Error.GetLastError() != Win32Error.ERROR_INSUFFICIENT_BUFFER)
            {
                return(false);
            }
            if (size < Marshal.SizeOf(typeof(T)))
            {
                throw new ArgumentException("Type mismatch", nameof(configInfo));
            }
            using (var buf = new SafeHGlobalHandle((int)size))
            {
                if (!QueryServiceConfig2(hService, dwInfoLevel, (IntPtr)buf, size, out size))
                {
                    return(false);
                }
                configInfo = buf.ToStructure <T>();
            }
            return(true);
        }
示例#2
0
 public static extern bool QueryServiceConfig2(IntPtr hService, ServiceConfigOption dwInfoLevel, IntPtr lpBuffer, uint cbBufSize, out uint pcbBytesNeeded);
示例#3
0
 public static extern bool ChangeServiceConfig2(IntPtr hService, ServiceConfigOption dwInfoLevel, IntPtr lpInfo);