List:Commits« Previous MessageNext Message »
From:Iggy Galarza Date:March 10 2011 3:47pm
Subject:bzr commit into wex-installer-1.0 branch (iggy:363)
View as plain text  
#At file:///C:/src/bzr.mysql/wex/installer/ based on revid:iggy@stripped

  363 Iggy Galarza	2011-03-10
      Centralized all the P/Invoke definitions.

    modified:
      StandardPlugins/Server/MysqlSCM.cs
      WexInstaller.Core/InstallerConfiguration.cs
      WexInstaller.Core/Win32.cs
      WexInstaller/Controls/ListViewHelper.cs
=== modified file 'StandardPlugins/Server/MysqlSCM.cs'
--- a/StandardPlugins/Server/MysqlSCM.cs	2011-03-09 12:44:28 +0000
+++ b/StandardPlugins/Server/MysqlSCM.cs	2011-03-10 15:47:49 +0000
@@ -13,6 +13,7 @@ using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
 using Microsoft.Win32;
+using MySQL.Utilities.SysUtils;
 
 // XXX: Use the System.ServiceProcess.ServiceInstaller class instead of P/Invoke for service installation!
 // Here's code to get you started: http://stackoverflow.com/questions/255056/install-a-net-windows-service-without-installutil-exe
@@ -197,101 +198,6 @@ namespace WexInstaller.Core
         #endregion
     }
 
-    internal static class SystemServiceProcessNativeMethods
-    {
-        #region Fields
-        public const int ACCESS_TYPE_ALL = 0xf01ff;
-        public const int ACCESS_TYPE_CHANGE_CONFIG = 2;
-        public const int ACCESS_TYPE_ENUMERATE_DEPENDENTS = 8;
-        public const int ACCESS_TYPE_INTERROGATE = 0x80;
-        public const int ACCESS_TYPE_PAUSE_CONTINUE = 0x40;
-        public const int ACCESS_TYPE_QUERY_CONFIG = 1;
-        public const int ACCESS_TYPE_QUERY_STATUS = 4;
-        public const int ACCESS_TYPE_START = 0x10;
-        public const int ACCESS_TYPE_STOP = 0x20;
-        public const int ACCESS_TYPE_DELETE = 0x00010000;
-        public const int ACCESS_TYPE_USER_DEFINED_CONTROL = 0x100;
-        public const int ERROR_CONTROL_CRITICAL = 3;
-        public const int ERROR_CONTROL_IGNORE = 0;
-        public const int ERROR_CONTROL_NORMAL = 1;
-        public const int ERROR_CONTROL_SEVERE = 2;
-        public const int SC_MANAGER_ALL = 0xf003f;
-        public const int SC_MANAGER_CONNECT = 1;
-        public const int SC_MANAGER_CREATE_SERVICE = 2;
-        public const int SC_MANAGER_ENUMERATE_SERVICE = 4;
-        public const int SC_MANAGER_LOCK = 8;
-        public const int SC_MANAGER_MODIFY_BOOT_CONFIG = 0x20;
-        public const int SC_MANAGER_QUERY_LOCK_STATUS = 0x10;
-        public const int START_TYPE_AUTO = 2;
-        public const int START_TYPE_BOOT = 0;
-        public const int START_TYPE_DEMAND = 3;
-        public const int START_TYPE_DISABLED = 4;
-        public const int START_TYPE_SYSTEM = 1;
-        public const int SERVICE_TYPE_ADAPTER = 4;
-        public const int SERVICE_TYPE_ALL = 0x13f;
-        public const int SERVICE_TYPE_DRIVER = 11;
-        public const int SERVICE_TYPE_FILE_SYSTEM_DRIVER = 2;
-        public const int SERVICE_TYPE_INTERACTIVE_PROCESS = 0x100;
-        public const int SERVICE_TYPE_KERNEL_DRIVER = 1;
-        public const int SERVICE_TYPE_RECOGNIZER_DRIVER = 8;
-        public const int SERVICE_TYPE_WIN32 = 0x30;
-        public const int SERVICE_TYPE_WIN32_OWN_PROCESS = 0x10;
-        public const int SERVICE_TYPE_WIN32_SHARE_PROCESS = 0x20;
-        #endregion
-
-        #region Methods
-        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
-        public static extern bool CloseServiceHandle(IntPtr handle);
-        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
-        public static extern IntPtr OpenSCManager(string machineName, string databaseName, int access);
-        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
-        public static extern IntPtr CreateService(IntPtr databaseHandle, string serviceName, string displayName, int access, int serviceType, int startType, int errorControl, string binaryPath, string loadOrderGroup, IntPtr pTagId, string dependencies, string servicesStartName, string password);
-        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
-        public static extern bool DeleteService(IntPtr serviceHandle);
-        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
-        public static extern IntPtr OpenService(IntPtr databaseHandle, string serviceName, int access);
-        #endregion
-
-        #region Nested Types
-        /*
-        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
-        public struct SC_ACTION
-        {
-            public int type;
-            public uint delay;
-        }
-        
-        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
-        public struct SERVICE_DESCRIPTION
-        {
-            public IntPtr description;
-        }
-        
-        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
-        public struct SERVICE_FAILURE_ACTIONS
-        {
-            public uint dwResetPeriod;
-            public IntPtr rebootMsg;
-            public IntPtr command;
-            public uint numActions;
-            public unsafe SystemServiceProcessNativeMethods.SC_ACTION* actions;
-        }
-        
-        [StructLayout(LayoutKind.Sequential)]
-        public struct SERVICE_STATUS
-        {
-            public int serviceType;
-            public int currentState;
-            public int controlsAccepted;
-            public int win32ExitCode;
-            public int serviceSpecificExitCode;
-            public int checkPoint;
-            public int waitHint;
-        }
-        */
-        #endregion
-    }
-
     // Wrapper for the ServiceController object that adds ability to Add and remove services and use service BinaryPath 
     public class ExpandedServiceController : ServiceController
     {
@@ -320,11 +226,11 @@ namespace WexInstaller.Core
             IntPtr zero = IntPtr.Zero;
             if (machineName.Equals(".") || (machineName.Length == 0))
             {
-                zero = SystemServiceProcessNativeMethods.OpenSCManager(null, null, (SystemServiceProcessNativeMethods.SC_MANAGER_ALL | SystemServiceProcessNativeMethods.ACCESS_TYPE_DELETE));
+                zero = Win32.OpenSCManager(null, null, (Win32.SC_MANAGER_ALL | Win32.ACCESS_TYPE_DELETE));
             }
             else
             {
-                zero = SystemServiceProcessNativeMethods.OpenSCManager(machineName, null, (SystemServiceProcessNativeMethods.SC_MANAGER_ALL | SystemServiceProcessNativeMethods.ACCESS_TYPE_DELETE));
+                zero = Win32.OpenSCManager(machineName, null, (Win32.SC_MANAGER_ALL | Win32.ACCESS_TYPE_DELETE));
             }
             if (zero == IntPtr.Zero)
             {
@@ -371,17 +277,17 @@ namespace WexInstaller.Core
 
             try
             {
-                IntPtr service = SystemServiceProcessNativeMethods.OpenService(scm, name, SystemServiceProcessNativeMethods.ACCESS_TYPE_ALL);
+                IntPtr service = Win32.OpenService(scm, name, Win32.ACCESS_TYPE_ALL);
 
                 if (service == IntPtr.Zero)
-                    service = SystemServiceProcessNativeMethods.CreateService(scm, name, displayName, SystemServiceProcessNativeMethods.ACCESS_TYPE_ALL, SystemServiceProcessNativeMethods.SERVICE_TYPE_WIN32_OWN_PROCESS, SystemServiceProcessNativeMethods.START_TYPE_AUTO, SystemServiceProcessNativeMethods.ERROR_CONTROL_NORMAL, fileName, null, IntPtr.Zero, null, null, null);
+                    service = Win32.CreateService(scm, name, displayName, Win32.ACCESS_TYPE_ALL, Win32.SERVICE_TYPE_WIN32_OWN_PROCESS, Win32.START_TYPE_AUTO, Win32.ERROR_CONTROL_NORMAL, fileName, null, IntPtr.Zero, null, null, null);
 
                 if (service == IntPtr.Zero)
                     throw CreateSafeWin32Exception();
             }
             finally
             {
-                SystemServiceProcessNativeMethods.CloseServiceHandle(scm);
+                Win32.CloseServiceHandle(scm);
             }
 
             this.ServiceName = name;
@@ -409,23 +315,23 @@ namespace WexInstaller.Core
 
             try
             {
-                IntPtr service = SystemServiceProcessNativeMethods.OpenService(scm, serviceName, SystemServiceProcessNativeMethods.ACCESS_TYPE_ALL | SystemServiceProcessNativeMethods.ACCESS_TYPE_DELETE);
+                IntPtr service = Win32.OpenService(scm, serviceName, Win32.ACCESS_TYPE_ALL | Win32.ACCESS_TYPE_DELETE);
                 if (service == IntPtr.Zero)
                     throw CreateSafeWin32Exception();
 
                 try
                 {
-                    if (!SystemServiceProcessNativeMethods.DeleteService(service))
+                    if (!Win32.DeleteService(service))
                         throw CreateSafeWin32Exception();
                 }
                 finally
                 {
-                    SystemServiceProcessNativeMethods.CloseServiceHandle(service);
+                    Win32.CloseServiceHandle(service);
                 }
             }
             finally
             {
-                SystemServiceProcessNativeMethods.CloseServiceHandle(scm);
+                Win32.CloseServiceHandle(scm);
             }
 
         }

=== modified file 'WexInstaller.Core/InstallerConfiguration.cs'
--- a/WexInstaller.Core/InstallerConfiguration.cs	2011-03-10 03:08:26 +0000
+++ b/WexInstaller.Core/InstallerConfiguration.cs	2011-03-10 15:47:49 +0000
@@ -8,6 +8,7 @@ using System.Drawing;
 using System.Runtime.InteropServices;
 using System.Diagnostics;
 using System.Net;
+using MySQL.Utilities.SysUtils;
 
 namespace WexInstaller.Core
 {
@@ -172,7 +173,7 @@ namespace WexInstaller.Core
         {
             bool isWow64 = false;
 
-            SystemNativeMethods.IsWow64Process(Process.GetCurrentProcess().Handle, out isWow64);
+            Win32.IsWow64Process(Process.GetCurrentProcess().Handle, out isWow64);
 
             return isWow64;
         }
@@ -204,10 +205,4 @@ namespace WexInstaller.Core
         }
         public string URL { get; set; }
     }
-
-    internal static class SystemNativeMethods
-    {
-        [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
-        public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lsSystemInfo);
-    }
 }

=== modified file 'WexInstaller.Core/Win32.cs'
--- a/WexInstaller.Core/Win32.cs	2011-03-03 15:21:07 +0000
+++ b/WexInstaller.Core/Win32.cs	2011-03-10 15:47:49 +0000
@@ -1,5 +1,6 @@
 using System;
 using System.Runtime.InteropServices;
+using System.Runtime.ConstrainedExecution;
 using System.Windows.Forms;
 using System.Diagnostics;
 using Microsoft.Win32.SafeHandles;
@@ -2440,6 +2441,45 @@ namespace MySQL.Utilities.SysUtils
     public const uint DWM_BB_BLURREGION = 0x00000002;
     public const uint DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004;
 
+    // Service Control stuff
+    public const int ACCESS_TYPE_ALL = 0xf01ff;
+    public const int ACCESS_TYPE_CHANGE_CONFIG = 2;
+    public const int ACCESS_TYPE_ENUMERATE_DEPENDENTS = 8;
+    public const int ACCESS_TYPE_INTERROGATE = 0x80;
+    public const int ACCESS_TYPE_PAUSE_CONTINUE = 0x40;
+    public const int ACCESS_TYPE_QUERY_CONFIG = 1;
+    public const int ACCESS_TYPE_QUERY_STATUS = 4;
+    public const int ACCESS_TYPE_START = 0x10;
+    public const int ACCESS_TYPE_STOP = 0x20;
+    public const int ACCESS_TYPE_DELETE = 0x00010000;
+    public const int ACCESS_TYPE_USER_DEFINED_CONTROL = 0x100;
+    public const int ERROR_CONTROL_CRITICAL = 3;
+    public const int ERROR_CONTROL_IGNORE = 0;
+    public const int ERROR_CONTROL_NORMAL = 1;
+    public const int ERROR_CONTROL_SEVERE = 2;
+    public const int SC_MANAGER_ALL = 0xf003f;
+    public const int SC_MANAGER_CONNECT = 1;
+    public const int SC_MANAGER_CREATE_SERVICE = 2;
+    public const int SC_MANAGER_ENUMERATE_SERVICE = 4;
+    public const int SC_MANAGER_LOCK = 8;
+    public const int SC_MANAGER_MODIFY_BOOT_CONFIG = 0x20;
+    public const int SC_MANAGER_QUERY_LOCK_STATUS = 0x10;
+    public const int START_TYPE_AUTO = 2;
+    public const int START_TYPE_BOOT = 0;
+    public const int START_TYPE_DEMAND = 3;
+    public const int START_TYPE_DISABLED = 4;
+    public const int START_TYPE_SYSTEM = 1;
+    public const int SERVICE_TYPE_ADAPTER = 4;
+    public const int SERVICE_TYPE_ALL = 0x13f;
+    public const int SERVICE_TYPE_DRIVER = 11;
+    public const int SERVICE_TYPE_FILE_SYSTEM_DRIVER = 2;
+    public const int SERVICE_TYPE_INTERACTIVE_PROCESS = 0x100;
+    public const int SERVICE_TYPE_KERNEL_DRIVER = 1;
+    public const int SERVICE_TYPE_RECOGNIZER_DRIVER = 8;
+    public const int SERVICE_TYPE_WIN32 = 0x30;
+    public const int SERVICE_TYPE_WIN32_OWN_PROCESS = 0x10;
+    public const int SERVICE_TYPE_WIN32_SHARE_PROCESS = 0x20;
+
     #region Structures and data types
 
     [StructLayout(LayoutKind.Sequential)]
@@ -2908,6 +2948,9 @@ namespace MySQL.Utilities.SysUtils
     [return: MarshalAs(UnmanagedType.Bool)]
     public static extern bool CloseHandle(IntPtr hHandle);
 
+    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
+    public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lsSystemInfo);
+
     [DllImport("dwmapi.dll", PreserveSig = false)]
     public static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DWM_BLURBEHIND pBlurBehind);
 
@@ -2937,6 +2980,21 @@ namespace MySQL.Utilities.SysUtils
     [DllImport("dwmapi.dll", PreserveSig = false)]
     public static extern void DwmQueryThumbnailSourceSize(IntPtr hThumbnail, out Size size);
 
+    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+    public static extern bool CloseServiceHandle(IntPtr handle);
+
+    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+    public static extern IntPtr OpenSCManager(string machineName, string databaseName, int access);
+
+    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+    public static extern IntPtr CreateService(IntPtr databaseHandle, string serviceName, string displayName, int access, int serviceType, int startType, int errorControl, string binaryPath, string loadOrderGroup, IntPtr pTagId, string dependencies, string servicesStartName, string password);
+
+    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+    public static extern bool DeleteService(IntPtr serviceHandle);
+
+    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+    public static extern IntPtr OpenService(IntPtr databaseHandle, string serviceName, int access);
+
     #endregion
 
     #region Helper methods

=== modified file 'WexInstaller/Controls/ListViewHelper.cs'
--- a/WexInstaller/Controls/ListViewHelper.cs	2010-08-24 23:50:30 +0000
+++ b/WexInstaller/Controls/ListViewHelper.cs	2011-03-10 15:47:49 +0000
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Text;
 using System.Runtime.InteropServices;
 using System.Windows.Forms;
+using MySQL.Utilities.SysUtils;
 
 namespace WexInstaller.Controls
 {
@@ -107,37 +108,34 @@ namespace WexInstaller.Controls
         {
         }
 
-        [DllImport("user32.dll", CharSet = CharSet.Auto)]
-        private static extern int SendMessage(IntPtr handle, int messg, int wparam, int lparam);
-
         public static void SetExtendedStyle(Control control, ListViewExtendedStyles exStyle)
         {
             ListViewExtendedStyles styles;
-            styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
+            styles = (ListViewExtendedStyles) Win32.SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
             styles |= exStyle;
-            SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);
+            Win32.SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (uint)styles);
         }
 
         public static void EnableDoubleBuffer(Control control)
         {
             ListViewExtendedStyles styles;
             // read current style
-            styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
+            styles = (ListViewExtendedStyles)Win32.SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
             // enable double buffer and border select
             styles |= ListViewExtendedStyles.DoubleBuffer | ListViewExtendedStyles.BorderSelect;
             // write new style
-            SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);
+            Win32.SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (uint)styles);
         }
         public static void DisableDoubleBuffer(Control control)
         {
             ListViewExtendedStyles styles;
             // read current style
-            styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
+            styles = (ListViewExtendedStyles) Win32.SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);
             // disable double buffer and border select
             styles -= styles & ListViewExtendedStyles.DoubleBuffer;
             styles -= styles & ListViewExtendedStyles.BorderSelect;
             // write new style
-            SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);
+            Win32.SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (uint)styles);
         }
     }
 }


Attachment: [text/bzr-bundle] bzr/iggy@mysql.com-20110310154749-5h5dy8hobmgvmg7w.bundle
Thread
bzr commit into wex-installer-1.0 branch (iggy:363) Iggy Galarza10 Mar