Get rid of some warnings
authorThomas
Wed, 10 Oct 2018 15:02:15 +0200
changeset 240186384b7195bb
parent 2400 0d9a4a2dc8f4
child 2402 b0701760bfae
Get rid of some warnings
Mapi.cs
NativeMethods.cs
Wrappers/WatchedExplorer.cs
     1.1 --- a/Mapi.cs	Wed Oct 10 13:52:41 2018 +0200
     1.2 +++ b/Mapi.cs	Wed Oct 10 15:02:15 2018 +0200
     1.3 @@ -175,7 +175,9 @@
     1.4              /// <summary>
     1.5              /// Reserved for MAPI; do not use.
     1.6              /// </summary>
     1.7 +#pragma warning disable 649
     1.8              public uint DwAlignPad;
     1.9 +#pragma warning restore 649
    1.10  
    1.11              /// <summary>
    1.12              /// Union of data values, the specific value dictated by the property type.
    1.13 @@ -277,7 +279,7 @@
    1.14              try
    1.15              {
    1.16                  // Initialize MAPI
    1.17 -                Mapi.MAPIInitialize(IntPtr.Zero);
    1.18 +                NativeMethods.MAPIInitialize(IntPtr.Zero);
    1.19  
    1.20                  // Get the IUnknown interface from the MAPI object
    1.21                  IUnknown = Marshal.GetIUnknownForObject(mapiObject);
    1.22 @@ -304,7 +306,7 @@
    1.23                  }
    1.24  
    1.25                  // Try to get the property
    1.26 -                Mapi.HrGetOneProp(IMAPIProp, mapiProperty.Tag, out ptrPropValue);
    1.27 +                NativeMethods.HrGetOneProp(IMAPIProp, mapiProperty.Tag, out ptrPropValue);
    1.28  
    1.29                  if (ptrPropValue == IntPtr.Zero)
    1.30                  {
    1.31 @@ -408,7 +410,7 @@
    1.32                  // Free used memory structures
    1.33                  if (ptrPropValue != IntPtr.Zero)
    1.34                  {
    1.35 -                    Mapi.MAPIFreeBuffer(ptrPropValue);
    1.36 +                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
    1.37                  }
    1.38  
    1.39                  // Clean up all references to COM Objects
    1.40 @@ -427,7 +429,7 @@
    1.41                      Marshal.Release(IUnknown);
    1.42                  }
    1.43  
    1.44 -                Mapi.MAPIUninitialize();
    1.45 +                NativeMethods.MAPIUninitialize();
    1.46              }
    1.47  
    1.48              return propertyValue;
    1.49 @@ -477,7 +479,7 @@
    1.50              try
    1.51              {
    1.52                  // Initialize MAPI
    1.53 -                Mapi.MAPIInitialize(IntPtr.Zero);
    1.54 +                NativeMethods.MAPIInitialize(IntPtr.Zero);
    1.55  
    1.56                  // Get the IUnknown interface from the MAPI object
    1.57                  IUnknown = Marshal.GetIUnknownForObject(mapiObject);
    1.58 @@ -674,7 +676,7 @@
    1.59                      Marshal.FreeHGlobal(valuePtr);
    1.60                  }
    1.61  
    1.62 -                Mapi.MAPIUninitialize();
    1.63 +                NativeMethods.MAPIUninitialize();
    1.64              }
    1.65  
    1.66              return success;
    1.67 @@ -730,7 +732,7 @@
    1.68              try
    1.69              {
    1.70                  // Initialize MAPI
    1.71 -                Mapi.MAPIInitialize(IntPtr.Zero);
    1.72 +                NativeMethods.MAPIInitialize(IntPtr.Zero);
    1.73  
    1.74                  // Get the IUnknown interface from the MAPI object
    1.75                  IUnknown = Marshal.GetIUnknownForObject(mapiObject);
    1.76 @@ -768,7 +770,7 @@
    1.77                  Marshal.StructureToPtr(propValue, ptrPropValue, false);
    1.78  
    1.79                  // Try to set the property
    1.80 -                Mapi.HrSetOneProp(IMAPIProp, ptrPropValue);
    1.81 +                NativeMethods.HrSetOneProp(IMAPIProp, ptrPropValue);
    1.82  
    1.83                  // Save changes
    1.84                  Mapi.IMAPIProp mapiProp = (Mapi.IMAPIProp)Marshal.GetTypedObjectForIUnknown(IUnknown, typeof(Mapi.IMAPIProp));
    1.85 @@ -784,7 +786,7 @@
    1.86                  // Free used memory structures
    1.87                  if (ptrPropValue != IntPtr.Zero)
    1.88                  {
    1.89 -                    Mapi.MAPIFreeBuffer(ptrPropValue);
    1.90 +                    NativeMethods.MAPIFreeBuffer(ptrPropValue);
    1.91                  }
    1.92  
    1.93                  // Clean up all references to COM Objects
    1.94 @@ -803,62 +805,11 @@
    1.95                      Marshal.Release(IUnknown);
    1.96                  }
    1.97  
    1.98 -                Mapi.MAPIUninitialize();
    1.99 +                NativeMethods.MAPIUninitialize();
   1.100              }
   1.101  
   1.102              return success;
   1.103          }
   1.104          #endregion
   1.105 -
   1.106 -        #region MAPI DLL Imports
   1.107 -        /// <summary>
   1.108 -        /// Increments the MAPI subsystem reference count and initializes global data for the MAPI DLL.
   1.109 -        /// </summary>
   1.110 -        /// <param name="mapiInit">Pointer to a MAPIINIT_0 structure. The mapiInit parameter can be set to IntPtr.Zero.</param>
   1.111 -        /// <returns>The status of this method.</returns>
   1.112 -        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi)]
   1.113 -        internal static extern int MAPIInitialize(IntPtr mapiInit);
   1.114 -
   1.115 -        /// <summary>
   1.116 -        /// Decrements the reference count, cleans up, and deletes per-instance global data for the MAPI DLL.
   1.117 -        /// </summary>
   1.118 -        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi)]
   1.119 -        internal static extern void MAPIUninitialize();
   1.120 -
   1.121 -        /// <summary>
   1.122 -        /// Retrieves the value of a single property from a property interface, that is, an interface derived from IMAPIProp.
   1.123 -        /// </summary>
   1.124 -        /// <param name="iMAPIProp">Pointer to the IMAPIProp interface from which the property value is to be retrieved.</param>
   1.125 -        /// <param name="propTag">Property tag of the property to be retrieved.</param>
   1.126 -        /// <param name="propertyValue">Pointer to a pointer to the returned SPropValue structure defining the retrieved property value.</param>
   1.127 -        /// <remarks>
   1.128 -        /// Unlike the IMAPIProp.GetProps method, the HrGetOneProp function never returns any warning.
   1.129 -        /// Because it retrieves only one property, it simply either succeeds or fails. For retrieving multiple properties,
   1.130 -        /// GetProps is faster.
   1.131 -        /// </remarks>
   1.132 -        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrGetOneProp@12")]
   1.133 -        internal static extern void HrGetOneProp(IntPtr iMAPIProp, uint propTag, out IntPtr propertyValue);
   1.134 -
   1.135 -        /// <summary>
   1.136 -        /// Sets or changes the value of a single property on a property interface, that is, an interface derived from IMAPIProp.
   1.137 -        /// </summary>
   1.138 -        /// <param name="iMAPIProp">Pointer to an IMAPIProp interface on which the property value is to be set or changed.</param>
   1.139 -        /// <param name="propertyValue">[in] Pointer to the SPropValue structure defining the property to be set or changed.</param>
   1.140 -        /// <remarks>
   1.141 -        /// Unlike the IMAPIProp::SetProps method, the HrSetOneProp function never returns any warning.
   1.142 -        /// Because it sets only one property, it simply either succeeds or fails.
   1.143 -        /// For setting or changing multiple properties, SetProps is faster. 
   1.144 -        /// </remarks>
   1.145 -        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrSetOneProp@8")]
   1.146 -        internal static extern void HrSetOneProp(IntPtr iMAPIProp, IntPtr propertyValue);
   1.147 -
   1.148 -        /// <summary>
   1.149 -        /// Frees a memory buffer allocated with a call to the MAPIAllocateBuffer function or the MAPIAllocateMore function.
   1.150 -        /// </summary>
   1.151 -        /// <param name="buffer">Pointer to a previously allocated memory buffer. If IntPtr.Zero is passed in the buffer parameter, MAPIFreeBuffer does nothing.</param>
   1.152 -        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "MAPIFreeBuffer@4")]
   1.153 -        internal static extern void MAPIFreeBuffer(IntPtr buffer);
   1.154 -        #endregion
   1.155 -
   1.156      }
   1.157  }
     2.1 --- a/NativeMethods.cs	Wed Oct 10 13:52:41 2018 +0200
     2.2 +++ b/NativeMethods.cs	Wed Oct 10 15:02:15 2018 +0200
     2.3 @@ -237,5 +237,55 @@
     2.4          [return: MarshalAs(UnmanagedType.Bool)]
     2.5          internal static extern bool SetCursorPos(int x, int y);
     2.6          #endregion
     2.7 +
     2.8 +        #region MAPI DLL Imports
     2.9 +        /// <summary>
    2.10 +        /// Increments the MAPI subsystem reference count and initializes global data for the MAPI DLL.
    2.11 +        /// </summary>
    2.12 +        /// <param name="mapiInit">Pointer to a MAPIINIT_0 structure. The mapiInit parameter can be set to IntPtr.Zero.</param>
    2.13 +        /// <returns>The status of this method.</returns>
    2.14 +        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi)]
    2.15 +        internal static extern int MAPIInitialize(IntPtr mapiInit);
    2.16 +
    2.17 +        /// <summary>
    2.18 +        /// Decrements the reference count, cleans up, and deletes per-instance global data for the MAPI DLL.
    2.19 +        /// </summary>
    2.20 +        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi)]
    2.21 +        internal static extern void MAPIUninitialize();
    2.22 +
    2.23 +        /// <summary>
    2.24 +        /// Retrieves the value of a single property from a property interface, that is, an interface derived from IMAPIProp.
    2.25 +        /// </summary>
    2.26 +        /// <param name="iMAPIProp">Pointer to the IMAPIProp interface from which the property value is to be retrieved.</param>
    2.27 +        /// <param name="propTag">Property tag of the property to be retrieved.</param>
    2.28 +        /// <param name="propertyValue">Pointer to a pointer to the returned SPropValue structure defining the retrieved property value.</param>
    2.29 +        /// <remarks>
    2.30 +        /// Unlike the IMAPIProp.GetProps method, the HrGetOneProp function never returns any warning.
    2.31 +        /// Because it retrieves only one property, it simply either succeeds or fails. For retrieving multiple properties,
    2.32 +        /// GetProps is faster.
    2.33 +        /// </remarks>
    2.34 +        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrGetOneProp@12")]
    2.35 +        internal static extern void HrGetOneProp(IntPtr iMAPIProp, uint propTag, out IntPtr propertyValue);
    2.36 +
    2.37 +        /// <summary>
    2.38 +        /// Sets or changes the value of a single property on a property interface, that is, an interface derived from IMAPIProp.
    2.39 +        /// </summary>
    2.40 +        /// <param name="iMAPIProp">Pointer to an IMAPIProp interface on which the property value is to be set or changed.</param>
    2.41 +        /// <param name="propertyValue">[in] Pointer to the SPropValue structure defining the property to be set or changed.</param>
    2.42 +        /// <remarks>
    2.43 +        /// Unlike the IMAPIProp::SetProps method, the HrSetOneProp function never returns any warning.
    2.44 +        /// Because it sets only one property, it simply either succeeds or fails.
    2.45 +        /// For setting or changing multiple properties, SetProps is faster. 
    2.46 +        /// </remarks>
    2.47 +        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrSetOneProp@8")]
    2.48 +        internal static extern void HrSetOneProp(IntPtr iMAPIProp, IntPtr propertyValue);
    2.49 +
    2.50 +        /// <summary>
    2.51 +        /// Frees a memory buffer allocated with a call to the MAPIAllocateBuffer function or the MAPIAllocateMore function.
    2.52 +        /// </summary>
    2.53 +        /// <param name="buffer">Pointer to a previously allocated memory buffer. If IntPtr.Zero is passed in the buffer parameter, MAPIFreeBuffer does nothing.</param>
    2.54 +        [DllImport("mapi32.DLL", CharSet = CharSet.Ansi, EntryPoint = "MAPIFreeBuffer@4")]
    2.55 +        internal static extern void MAPIFreeBuffer(IntPtr buffer);
    2.56 +        #endregion
    2.57      }
    2.58  }
     3.1 --- a/Wrappers/WatchedExplorer.cs	Wed Oct 10 13:52:41 2018 +0200
     3.2 +++ b/Wrappers/WatchedExplorer.cs	Wed Oct 10 15:02:15 2018 +0200
     3.3 @@ -67,6 +67,8 @@
     3.4  
     3.5                  // Set Outlook objects to null
     3.6                  this.explorer = null;
     3.7 +
     3.8 +                // Dispose the inline response item
     3.9                  this.inlineResponseItem?.Dispose();
    3.10                  this.inlineResponseItem = null;
    3.11              }
    3.12 @@ -127,7 +129,7 @@
    3.13               * securely instead of to the server's draft folder.
    3.14               * Note: the form region's CMI is already disposed at this point,
    3.15               * so that its Write event will never be called.
    3.16 -             */ 
    3.17 +             */
    3.18              try
    3.19              {
    3.20                  omi = this.explorer?.ActiveInlineResponse as Outlook.MailItem;