diff --git a/.gitmodules b/.gitmodules index 4f1daea81..4164cc8ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "Samples"] path = Samples url = git@github.com:sharpdx/SharpDX-Samples.git +[submodule "deps/CoreFX"] + path = deps/CoreFX + url = git@github.com:manu-silicon/corefxref.git diff --git a/Build/SharpDX.PreSettings.targets b/Build/SharpDX.PreSettings.targets index 95f46d197..8a11e1870 100644 --- a/Build/SharpDX.PreSettings.targets +++ b/Build/SharpDX.PreSettings.targets @@ -12,6 +12,7 @@ false AnyCPU Desktop + CoreCLR false @@ -37,9 +38,14 @@ + + $(SolutionDir)\deps\CoreFX + $(SolutionDir)\deps\CoreFX\CoreCLR\v5.0 + $(SolutionDir)\deps\CoreFX\configs\CoreCLR.CSharp.targets @@ -47,6 +53,11 @@ Profile32 v4.6 $(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets + @@ -91,6 +102,10 @@ $(DefineConstants);DESKTOP_APP + + $(DefineConstants);CORECLR + + $(DefineConstants);STORE_APP;WINDOWS_API_SET @@ -107,4 +122,4 @@ OnBuildSuccess - \ No newline at end of file + diff --git a/SharpDX-Desktop.sln b/SharpDX-Desktop.sln index 0cf86bb37..54304b326 100644 --- a/SharpDX-Desktop.sln +++ b/SharpDX-Desktop.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31010.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sources", "Sources", "{CC8DB471-0644-430D-9D4B-808A2475BEC0}" ProjectSection(SolutionItems) = preProject diff --git a/Source/SharpDX.Desktop/MessageFilterHook.cs b/Source/SharpDX.Desktop/MessageFilterHook.cs index c3b08c630..f8fc0aca4 100644 --- a/Source/SharpDX.Desktop/MessageFilterHook.cs +++ b/Source/SharpDX.Desktop/MessageFilterHook.cs @@ -21,7 +21,11 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; +#if !CORECLR using System.Windows.Forms; +#else +using SharpDX.RawInput; +#endif using SharpDX.Collections; namespace SharpDX @@ -61,14 +65,14 @@ private MessageFilterHook(IntPtr hwnd) this.hwnd = hwnd; // Retrieve the previous WndProc associated with this window handle - defaultWndProc = Win32Native.GetWindowLong(new HandleRef(this, hwnd), Win32Native.WindowLongType.WndProc); + defaultWndProc = Win32Native.GetWindowLong(hwnd, Win32Native.WindowLongType.WndProc); // Create a pointer to the new WndProc newWndProc = WndProc; newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc); // Set our own private wndproc in order to catch NCDestroy message - Win32Native.SetWindowLong(new HandleRef(this, hwnd), Win32Native.WindowLongType.WndProc, newWndProcPtr); + Win32Native.SetWindowLong(hwnd, Win32Native.WindowLongType.WndProc, newWndProcPtr); } #endregion @@ -149,11 +153,11 @@ private void RemoveMessageFilter(IMessageFilter filter) private void RestoreWndProc() { - var currentProc = Win32Native.GetWindowLong(new HandleRef(this, hwnd), Win32Native.WindowLongType.WndProc); + var currentProc = Win32Native.GetWindowLong(hwnd, Win32Native.WindowLongType.WndProc); if (currentProc == newWndProcPtr) { // Restore back default WndProc only if the previous callback is owned by this message filter hook - Win32Native.SetWindowLong(new HandleRef(this, hwnd), Win32Native.WindowLongType.WndProc, defaultWndProc); + Win32Native.SetWindowLong(hwnd, Win32Native.WindowLongType.WndProc, defaultWndProc); } } @@ -177,9 +181,14 @@ private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) private static IntPtr GetSafeWindowHandle(IntPtr hwnd) { +#if !CORECLR return hwnd == IntPtr.Zero ? Process.GetCurrentProcess().MainWindowHandle : hwnd; +#else + // We assume in CoreCLR that `hwnd' is indeed a valid HWND handle. + return hwnd; +#endif } #endregion } -} \ No newline at end of file +} diff --git a/Source/SharpDX.Desktop/Properties/Resources.Designer.cs b/Source/SharpDX.Desktop/Properties/Resources.Designer.cs index e7fe644c6..360f17867 100644 --- a/Source/SharpDX.Desktop/Properties/Resources.Designer.cs +++ b/Source/SharpDX.Desktop/Properties/Resources.Designer.cs @@ -10,6 +10,7 @@ namespace SharpDX.Desktop.Properties { using System; + using System.Reflection; /// @@ -39,7 +40,7 @@ internal Resources() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpDX.Desktop.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpDX.Desktop.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; @@ -60,6 +61,7 @@ internal Resources() { } } +#if !CORECLR /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -69,5 +71,6 @@ internal static System.Drawing.Icon logo { return ((System.Drawing.Icon)(obj)); } } +#endif } } diff --git a/Source/SharpDX.Desktop/RenderForm.cs b/Source/SharpDX.Desktop/RenderForm.cs index 2d11639db..8a3632bd8 100644 --- a/Source/SharpDX.Desktop/RenderForm.cs +++ b/Source/SharpDX.Desktop/RenderForm.cs @@ -43,6 +43,7 @@ * THE SOFTWARE. */ +#if !CORECLR using System.Diagnostics; using SharpDX.Mathematics.Interop; using System; @@ -448,4 +449,5 @@ protected override bool ProcessDialogKey(Keys keyData) return base.ProcessDialogKey(keyData); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Source/SharpDX.Desktop/RenderLoop.cs b/Source/SharpDX.Desktop/RenderLoop.cs index e93ded372..164d7319b 100644 --- a/Source/SharpDX.Desktop/RenderLoop.cs +++ b/Source/SharpDX.Desktop/RenderLoop.cs @@ -20,13 +20,47 @@ using System; using System.Globalization; +#if !CORECLR using System.Windows.Forms; +#else +using SharpDX.RawInput; +#endif using System.Runtime.InteropServices; using SharpDX.Win32; namespace SharpDX.Windows { + +#if CORECLR + /// + /// Interface to mimic the System.Windows.Forms.Control class to minimize the amount + /// of code to change when not using System.Windows.Forms. + /// + public interface Control + { + /// + /// Access to the underlying Win32 HWND handle. + /// + IntPtr Handle { get; } + + /// + /// Indicates whether the control has been disposed. + /// + bool IsDisposed { get; } + + /// + /// Show form. + /// + void Show(); + + /// + /// Adds a event handler to listen to the Disposed event on the component. + /// + event EventHandler Disposed; + } +#endif + /// /// RenderLoop provides a rendering loop infrastructure. See remarks for usage. /// @@ -130,7 +164,9 @@ public bool NextFrame() // Revert back to Application.DoEvents in order to support Application.AddMessageFilter // Seems that DoEvents is compatible with Mono unlike Application.Run that was not running // correctly. +#if !CORECLR Application.DoEvents(); +#endif } else { @@ -155,7 +191,9 @@ public bool NextFrame() } var message = new Message() { HWnd = msg.handle, LParam = msg.lParam, Msg = (int)msg.msg, WParam = msg.wParam }; +#if !CORECLR if (!Application.FilterMessage(ref message)) +#endif { Win32Native.TranslateMessage(ref msg); Win32Native.DispatchMessage(ref msg); @@ -186,6 +224,7 @@ public void Dispose() /// public delegate void RenderCallback(); +#if !CORECLR /// /// Runs the specified main loop in the specified context. /// @@ -193,6 +232,7 @@ public static void Run(ApplicationContext context, RenderCallback renderCallback { Run(context.MainForm, renderCallback); } +#endif /// /// Runs the specified main loop for the specified windows form. diff --git a/Source/SharpDX.Desktop/SharpDX.Desktop.csproj b/Source/SharpDX.Desktop/SharpDX.Desktop.csproj index 9e86ab1e8..4c933f688 100644 --- a/Source/SharpDX.Desktop/SharpDX.Desktop.csproj +++ b/Source/SharpDX.Desktop/SharpDX.Desktop.csproj @@ -30,10 +30,10 @@ True True - + UserControl - + Form @@ -46,6 +46,10 @@ + + {05d17a7b-f200-48c0-b8f9-b7211665a17f} + SharpDX.RawInput + {d0bcd56a-41c4-4a4e-8590-26864ced07ff} SharpDX diff --git a/Source/SharpDX.Desktop/Win32Native.cs b/Source/SharpDX.Desktop/Win32Native.cs index cf4278fd6..9d4ef8994 100644 --- a/Source/SharpDX.Desktop/Win32Native.cs +++ b/Source/SharpDX.Desktop/Win32Native.cs @@ -68,18 +68,19 @@ public struct TextMetric public byte tmCharSet; } - [DllImport("user32.dll", EntryPoint = "PeekMessage"), SuppressUnmanagedCodeSecurity] + + [DllImport("user32.dll", EntryPoint = "PeekMessage")] public static extern int PeekMessage(out NativeMessage lpMsg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax, int wRemoveMsg); - [DllImport("user32.dll", EntryPoint = "GetMessage"), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", EntryPoint = "GetMessage")] public static extern int GetMessage(out NativeMessage lpMsg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax); - [DllImport("user32.dll", EntryPoint = "TranslateMessage"), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", EntryPoint = "TranslateMessage")] public static extern int TranslateMessage(ref NativeMessage lpMsg); - [DllImport("user32.dll", EntryPoint = "DispatchMessage"), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", EntryPoint = "DispatchMessage")] public static extern int DispatchMessage(ref NativeMessage lpMsg); public enum WindowLongType : int @@ -95,7 +96,7 @@ public enum WindowLongType : int public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); - public static IntPtr GetWindowLong(HandleRef hWnd, WindowLongType index) + public static IntPtr GetWindowLong(IntPtr hWnd, WindowLongType index) { if (IntPtr.Size == 4) { @@ -108,12 +109,12 @@ public static IntPtr GetWindowLong(HandleRef hWnd, WindowLongType index) public static extern IntPtr GetFocus(); [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Unicode)] - private static extern IntPtr GetWindowLong32(HandleRef hwnd, WindowLongType index); + private static extern IntPtr GetWindowLong32(IntPtr hwnd, WindowLongType index); [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Unicode)] - private static extern IntPtr GetWindowLong64(HandleRef hwnd, WindowLongType index); + private static extern IntPtr GetWindowLong64(IntPtr hwnd, WindowLongType index); - public static IntPtr SetWindowLong(HandleRef hwnd, WindowLongType index, IntPtr wndProcPtr) + public static IntPtr SetWindowLong(IntPtr hwnd, WindowLongType index, IntPtr wndProcPtr) { if (IntPtr.Size == 4) { @@ -123,22 +124,22 @@ public static IntPtr SetWindowLong(HandleRef hwnd, WindowLongType index, IntPtr } [DllImport("user32.dll", EntryPoint = "SetParent", CharSet = CharSet.Unicode)] - public static extern IntPtr SetParent(HandleRef hWnd, IntPtr hWndParent); + public static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent); [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Unicode)] - private static extern IntPtr SetWindowLong32(HandleRef hwnd, WindowLongType index, IntPtr wndProc); + private static extern IntPtr SetWindowLong32(IntPtr hwnd, WindowLongType index, IntPtr wndProc); - public static bool ShowWindow(HandleRef hWnd, bool windowVisible) + public static bool ShowWindow(IntPtr hWnd, bool windowVisible) { return ShowWindow(hWnd, windowVisible ? 1 : 0); } [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Unicode)] - private static extern bool ShowWindow(HandleRef hWnd, int mCmdShow); + private static extern bool ShowWindow(IntPtr hWnd, int mCmdShow); [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Unicode)] - private static extern IntPtr SetWindowLongPtr64(HandleRef hwnd, WindowLongType index, IntPtr wndProc); + private static extern IntPtr SetWindowLongPtr64(IntPtr hwnd, WindowLongType index, IntPtr wndProc); [DllImport("user32.dll", EntryPoint = "CallWindowProc", CharSet = CharSet.Unicode)] public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam); diff --git a/Source/SharpDX.Direct3D9/Device.cs b/Source/SharpDX.Direct3D9/Device.cs index 580c185d4..4569ef961 100644 --- a/Source/SharpDX.Direct3D9/Device.cs +++ b/Source/SharpDX.Direct3D9/Device.cs @@ -20,6 +20,7 @@ using System; using System.Globalization; +using System.Reflection; using SharpDX.Mathematics.Interop; namespace SharpDX.Direct3D9 @@ -628,7 +629,7 @@ public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectan } - /// +#if !CORECLR /// Presents the contents of the next buffer in the sequence of back buffers to the screen. /// /// The area of the back buffer that should be presented. @@ -647,6 +648,7 @@ public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectan Present(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, regionPtr); } } +#endif /// /// Resets the stream source frequency by setting the frequency to 1. @@ -944,7 +946,7 @@ public void SetRenderState(RenderState renderState, float value) /// HRESULT IDirect3DDevice9::SetRenderState([In] D3DRENDERSTATETYPE State,[In] unsigned int Value) public void SetRenderState(RenderState renderState, T value) where T : struct, IConvertible { - if (!typeof(T).IsEnum) + if (!typeof(T).GetTypeInfo().IsEnum) throw new ArgumentException("T must be an enum type", "value"); SetRenderState(renderState, value.ToInt32(CultureInfo.InvariantCulture)); diff --git a/Source/SharpDX.Direct3D9/DeviceEx.cs b/Source/SharpDX.Direct3D9/DeviceEx.cs index def1f2646..882b46e14 100644 --- a/Source/SharpDX.Direct3D9/DeviceEx.cs +++ b/Source/SharpDX.Direct3D9/DeviceEx.cs @@ -18,7 +18,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +#if !CORECLR using System.Drawing; +#endif using SharpDX.Mathematics.Interop; namespace SharpDX.Direct3D9 @@ -200,7 +202,7 @@ public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle } } - /// +#if !CORECLR /// Swap the swapchain's next buffer with the front buffer. /// /// The flags. @@ -222,6 +224,7 @@ public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, regionPtr, (int)flags); } } +#endif /// /// Resets the type, size, and format of the swap chain with all other surfaces persistent. diff --git a/Source/SharpDX.Direct3D9/EffectHandle.cs b/Source/SharpDX.Direct3D9/EffectHandle.cs index 903dab976..e0c504c6b 100644 --- a/Source/SharpDX.Direct3D9/EffectHandle.cs +++ b/Source/SharpDX.Direct3D9/EffectHandle.cs @@ -178,8 +178,10 @@ private static IntPtr AllocateString(string name) IntPtr value; if (UseCacheStrings) { +#if !CORECLR // internalize the string in order to have a faster comparison with the dictionary name = string.Intern(name); +#endif lock (AllocatedStrings) { if (!AllocatedStrings.TryGetValue(name, out value)) diff --git a/Source/SharpDX.Direct3D9/Font.cs b/Source/SharpDX.Direct3D9/Font.cs index fc184e7f1..11d5f4469 100644 --- a/Source/SharpDX.Direct3D9/Font.cs +++ b/Source/SharpDX.Direct3D9/Font.cs @@ -36,6 +36,7 @@ public Font(Device device, FontDescription fontDescription) : base(IntPtr.Zero) D3DX9.CreateFontIndirect(device, ref fontDescription, this); } +#if !CORECLR /// /// Initializes a new instance of the class from a /// @@ -45,6 +46,7 @@ public Font(Device device, System.Drawing.Font font) { D3DX9.CreateFont(device, font.Height, 0, (int)(font.Bold ? FontWeight.Bold : FontWeight.Normal), 0, font.Italic, (int)FontCharacterSet.Default, (int)FontPrecision.Default, (int)FontQuality.Default, (int)FontPitchAndFamily.Default, font.Name, this); } +#endif /// /// Initializes a new instance of the class. diff --git a/Source/SharpDX.Direct3D9/SwapChain.cs b/Source/SharpDX.Direct3D9/SwapChain.cs index 70306abe5..06142d233 100644 --- a/Source/SharpDX.Direct3D9/SwapChain.cs +++ b/Source/SharpDX.Direct3D9/SwapChain.cs @@ -93,7 +93,7 @@ public void Present(Present presentFlags, RawRectangle sourceRectangle, RawRecta } } - +#if !CORECLR /// /// Presents the contents of the next buffer in the sequence of back buffers to the screen. /// @@ -122,6 +122,7 @@ public void Present(Present flags, RawRectangle sourceRectangle, RawRectangle de Present(srcPtr, destPtr, windowOverride, regionPtr, (int)flags); } } +#endif } } \ No newline at end of file diff --git a/Source/SharpDX.DirectComposition/DesktopDevice.cs b/Source/SharpDX.DirectComposition/DesktopDevice.cs index ef2494399..ef0d6425b 100644 --- a/Source/SharpDX.DirectComposition/DesktopDevice.cs +++ b/Source/SharpDX.DirectComposition/DesktopDevice.cs @@ -88,7 +88,7 @@ public static bool GetWindowIsCloaked(IntPtr hwnd) /// public static void SetWindowIsLayered(IntPtr hwnd, bool isLayered) { - if (Environment.Is64BitProcess) + if (Is64BitProcess()) { IntPtr exStyle = NativeMethods.GetWindowLongPtr(hwnd, NativeMethods.GWL_EXSTYLE); if (exStyle == IntPtr.Zero) @@ -115,7 +115,7 @@ public static void SetWindowIsLayered(IntPtr hwnd, bool isLayered) /// True if the window has the layered style applied, false otherwise. public static bool GetWindowIsLayered(IntPtr hwnd) { - if (Environment.Is64BitProcess) + if (Is64BitProcess()) { IntPtr exStyle = NativeMethods.GetWindowLongPtr(hwnd, NativeMethods.GWL_EXSTYLE); if (exStyle == IntPtr.Zero) @@ -130,5 +130,13 @@ public static bool GetWindowIsLayered(IntPtr hwnd) return (exStyle & NativeMethods.WS_EX_LAYERED) == NativeMethods.WS_EX_LAYERED; } } + + /// + /// Finds out if we are a 64-bit process or not. + /// + private static bool Is64BitProcess() + { + return (IntPtr.Size == 8); + } } } diff --git a/Source/SharpDX.DirectInput/CustomDevice.cs b/Source/SharpDX.DirectInput/CustomDevice.cs index f739dc3a7..393a30ee7 100644 --- a/Source/SharpDX.DirectInput/CustomDevice.cs +++ b/Source/SharpDX.DirectInput/CustomDevice.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Reflection; using System.Runtime.InteropServices; +using System.Linq; namespace SharpDX.DirectInput { @@ -133,21 +134,21 @@ private DataFormat GetDataFormat() else { // Build DataFormat from DataFormat and DataObjectFormat attributes - var dataFormatAttributes = typeof (TRaw).GetCustomAttributes(typeof (DataFormatAttribute), false); - if (dataFormatAttributes.Length != 1) + IEnumerable dataFormatAttributes = typeof(TRaw).GetTypeInfo().GetCustomAttributes(false); + if (dataFormatAttributes.Count() != 1) throw new InvalidOperationException( string.Format(System.Globalization.CultureInfo.InvariantCulture, "The structure [{0}] must be marked with DataFormatAttribute or provide a IDataFormatProvider", typeof (TRaw).FullName)); - _dataFormat = new DataFormat(((DataFormatAttribute) dataFormatAttributes[0]).Flags) {DataSize = Utilities.SizeOf()}; + _dataFormat = new DataFormat(((DataFormatAttribute) dataFormatAttributes.First()).Flags) {DataSize = Utilities.SizeOf()}; var dataObjects = new List(); // Iterates on fields foreach (var field in typeof(TRaw).GetFields(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance)) { - var dataObjectAttributes = field.GetCustomAttributes(typeof (DataObjectFormatAttribute), false); - if (dataObjectAttributes.Length > 0) + IEnumerable dataObjectAttributes = field.GetCustomAttributes(false); + if (dataObjectAttributes.Count() > 0) { int fieldOffset = Marshal.OffsetOf(typeof (TRaw), field.Name).ToInt32(); int totalSizeOfField = Marshal.SizeOf(field.FieldType); @@ -156,9 +157,9 @@ private DataFormat GetDataFormat() // Count the number of effective sub-field for a field // A field that contains a fixed array should have sub-field - for (int i = 0; i < dataObjectAttributes.Length; i++) + for (int i = 0; i < dataObjectAttributes.Count(); i++) { - var attr = ((DataObjectFormatAttribute) dataObjectAttributes[i]); + var attr = dataObjectAttributes.ElementAt(i); numberOfDataObjects += attr.ArrayCount == 0 ? 1 : attr.ArrayCount; } @@ -171,10 +172,10 @@ private DataFormat GetDataFormat() int subFieldIndex = 0; // Iterates on attributes - for (int i = 0; i < dataObjectAttributes.Length; i++) + for (int i = 0; i < dataObjectAttributes.Count(); i++) { - var attr = ((DataObjectFormatAttribute) dataObjectAttributes[i]); + var attr = dataObjectAttributes.ElementAt(i); numberOfDataObjects = attr.ArrayCount == 0 ? 1 : attr.ArrayCount; // Add DataObjectFormat diff --git a/Source/SharpDX.DirectInput/Device.cs b/Source/SharpDX.DirectInput/Device.cs index f72a6c733..4c0982232 100644 --- a/Source/SharpDX.DirectInput/Device.cs +++ b/Source/SharpDX.DirectInput/Device.cs @@ -20,7 +20,9 @@ using System; using System.Collections.Generic; using System.Threading; +#if !CORECLR using System.Windows.Forms; +#endif namespace SharpDX.DirectInput { @@ -226,10 +228,17 @@ public void RunControlPanel() /// /// The parent control. /// A object describing the result of the operation. +#if !CORECLR public void RunControlPanel(Control parent) { RunControlPanel(parent.Handle, 0); } +#else + public void RunControlPanel(IntPtr hwnd) + { + RunControlPanel(hwnd, 0); + } +#endif // Disabled as it seems to be not used anymore @@ -261,11 +270,12 @@ public void RunControlPanel(Control parent) /// Applications must call this method before acquiring the device by using the method. /// /// HRESULT IDirectInputDevice8W::SetCooperativeLevel([In] HWND arg0,[In] DISCL arg1) +#if !CORECLR public void SetCooperativeLevel(Control control, CooperativeLevel level) { SetCooperativeLevel(control.Handle, level); } - +#endif /// /// Specifies an event that is to be set when the device state changes. It is also used to turn off event notification. /// @@ -273,7 +283,11 @@ public void SetCooperativeLevel(Control control, CooperativeLevel level) /// A object describing the result of the operation. public void SetNotification(WaitHandle eventHandle) { +#if !CORECLR SetEventNotification(eventHandle!=null?eventHandle.SafeWaitHandle.DangerousGetHandle():IntPtr.Zero); +#else + SetEventNotification(eventHandle!=null?eventHandle.GetSafeWaitHandle().DangerousGetHandle():IntPtr.Zero); +#endif } /// diff --git a/Source/SharpDX.DirectSound/NotificationPosition.cs b/Source/SharpDX.DirectSound/NotificationPosition.cs index 349c558af..dc60e6a1b 100644 --- a/Source/SharpDX.DirectSound/NotificationPosition.cs +++ b/Source/SharpDX.DirectSound/NotificationPosition.cs @@ -52,7 +52,11 @@ internal unsafe void __MarshalFree(ref __Native @ref) internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Offset = this.Offset; +#if !CORECLR @ref.EventNotifyHandlerPointer = this.WaitHandle.SafeWaitHandle.DangerousGetHandle(); +#else + @ref.EventNotifyHandlerPointer = this.WaitHandle.GetSafeWaitHandle().DangerousGetHandle(); +#endif } } } \ No newline at end of file diff --git a/Source/SharpDX.MediaFoundation/AudioDecoder.cs b/Source/SharpDX.MediaFoundation/AudioDecoder.cs index add011178..48933a76a 100644 --- a/Source/SharpDX.MediaFoundation/AudioDecoder.cs +++ b/Source/SharpDX.MediaFoundation/AudioDecoder.cs @@ -23,7 +23,7 @@ using SharpDX.Multimedia; -#if STORE_APP +#if STORE_APP && !CORECLR using Windows.Storage.Streams; #endif @@ -82,7 +82,7 @@ public void SetSourceStream(Stream value) } } -#if STORE_APP +#if STORE_APP && !CORECLR /// /// Initializes a new instance of the class. /// diff --git a/Source/SharpDX.MediaFoundation/ByteStream.cs b/Source/SharpDX.MediaFoundation/ByteStream.cs index 07087ce92..a504c4702 100644 --- a/Source/SharpDX.MediaFoundation/ByteStream.cs +++ b/Source/SharpDX.MediaFoundation/ByteStream.cs @@ -25,7 +25,7 @@ using SharpDX.Win32; using SharpDX.IO; -#if STORE_APP +#if STORE_APP && !CORECLR using Windows.Storage.Streams; #endif @@ -72,7 +72,7 @@ public ByteStream(byte[] sourceStream) : this(new MemoryStream(sourceStream)) { } -#if STORE_APP +#if STORE_APP && !CORECLR /// /// Instantiates a new instance from a . /// diff --git a/Source/SharpDX.MediaFoundation/SourceReader.cs b/Source/SharpDX.MediaFoundation/SourceReader.cs index ac25437a1..e6a910975 100644 --- a/Source/SharpDX.MediaFoundation/SourceReader.cs +++ b/Source/SharpDX.MediaFoundation/SourceReader.cs @@ -22,7 +22,7 @@ using System; using System.IO; -#if STORE_APP +#if STORE_APP && !CORECLR using Windows.Storage.Streams; #endif @@ -100,7 +100,7 @@ public SourceReader(MediaSource source, MediaAttributes attributes = null) { MediaFactory.CreateSourceReaderFromMediaSource(source, attributes, this); } -#if STORE_APP +#if STORE_APP && !CORECLR /// /// Creates the source reader from a byte stream. /// diff --git a/Source/SharpDX.RawInput/Device.cs b/Source/SharpDX.RawInput/Device.cs index 20e5b6806..82a22267c 100644 --- a/Source/SharpDX.RawInput/Device.cs +++ b/Source/SharpDX.RawInput/Device.cs @@ -21,7 +21,9 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +#if !CORECLR using System.Windows.Forms; +#endif using SharpDX.Multimedia; using SharpDX.Win32; @@ -126,6 +128,7 @@ public static void RegisterDevice(UsagePage usagePage, UsageId usageId, DeviceFl if (options != RegisterDeviceOptions.NoFiltering && rawInputMessageFilter == null) { rawInputMessageFilter = new RawInputMessageFilter(); +#if !CORECLR if (options == RegisterDeviceOptions.Default) { Application.AddMessageFilter(rawInputMessageFilter); @@ -134,6 +137,9 @@ public static void RegisterDevice(UsagePage usagePage, UsageId usageId, DeviceFl { MessageFilterHook.AddMessageFilter(target, rawInputMessageFilter); } +#else + MessageFilterHook.AddMessageFilter(target, rawInputMessageFilter); +#endif } } diff --git a/Source/SharpDX.RawInput/IMessageFilter.cs b/Source/SharpDX.RawInput/IMessageFilter.cs new file mode 100644 index 000000000..4ae5c172b --- /dev/null +++ b/Source/SharpDX.RawInput/IMessageFilter.cs @@ -0,0 +1,34 @@ +// Copyright (c) 2010-2015 SharpDX - Alexandre Mutel +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if CORECLR + +namespace SharpDX.RawInput +{ + /// + /// Facade class to get most of the SharpDX code compile even if compiled against CoreCLR which does not provide Winforms. + /// + public interface IMessageFilter + { + bool PreFilterMessage(ref Message m); + } +} + +#endif \ No newline at end of file diff --git a/Source/SharpDX.RawInput/KeyboardInputEventArgs.cs b/Source/SharpDX.RawInput/KeyboardInputEventArgs.cs index 1db8559f6..90adc716c 100644 --- a/Source/SharpDX.RawInput/KeyboardInputEventArgs.cs +++ b/Source/SharpDX.RawInput/KeyboardInputEventArgs.cs @@ -17,7 +17,10 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. + +#if !CORECLR using System.Windows.Forms; +#endif namespace SharpDX.RawInput { diff --git a/Source/SharpDX.RawInput/Keys.cs b/Source/SharpDX.RawInput/Keys.cs new file mode 100644 index 000000000..a0393fdd0 --- /dev/null +++ b/Source/SharpDX.RawInput/Keys.cs @@ -0,0 +1,226 @@ +// Copyright (c) 2010-2015 SharpDX - Alexandre Mutel +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if CORECLR +namespace SharpDX.RawInput +{ + /// + /// List of Keys constants usually provided by Winforms but the later is not available in CoreCLR. + /// + public enum Keys + { + KeyCode = 0x0000FFFF, + Modifiers = unchecked((int)0xFFFF0000), + None = 0x00, + LButton = 0x01, + RButton = 0x02, + Cancel = 0x03, + MButton = 0x04, + XButton1 = 0x05, + XButton2 = 0x06, + Back = 0x08, + Tab = 0x09, + LineFeed = 0x0A, + Clear = 0x0C, + Return = 0x0D, + Enter = Return, + ShiftKey = 0x10, + ControlKey = 0x11, + Menu = 0x12, + Pause = 0x13, + Capital = 0x14, + CapsLock = 0x14, + KanaMode = 0x15, + HanguelMode = 0x15, + HangulMode = 0x15, + JunjaMode = 0x17, + FinalMode = 0x18, + HanjaMode = 0x19, + KanjiMode = 0x19, + Escape = 0x1B, + IMEConvert = 0x1C, + IMENonconvert = 0x1D, + IMEAccept = 0x1E, + IMEAceept = IMEAccept, + IMEModeChange = 0x1F, + Space = 0x20, + Prior = 0x21, + PageUp = Prior, + Next = 0x22, + PageDown = Next, + End = 0x23, + Home = 0x24, + Left = 0x25, + Up = 0x26, + Right = 0x27, + Down = 0x28, + Select = 0x29, + Print = 0x2A, + Execute = 0x2B, + Snapshot = 0x2C, + PrintScreen = Snapshot, + Insert = 0x2D, + Delete = 0x2E, + Help = 0x2F, + D0 = 0x30, // 0 + D1 = 0x31, // 1 + D2 = 0x32, // 2 + D3 = 0x33, // 3 + D4 = 0x34, // 4 + D5 = 0x35, // 5 + D6 = 0x36, // 6 + D7 = 0x37, // 7 + D8 = 0x38, // 8 + D9 = 0x39, // 9 + A = 0x41, + B = 0x42, + C = 0x43, + D = 0x44, + E = 0x45, + F = 0x46, + G = 0x47, + H = 0x48, + I = 0x49, + J = 0x4A, + K = 0x4B, + L = 0x4C, + M = 0x4D, + N = 0x4E, + O = 0x4F, + P = 0x50, + Q = 0x51, + R = 0x52, + S = 0x53, + T = 0x54, + U = 0x55, + V = 0x56, + W = 0x57, + X = 0x58, + Y = 0x59, + Z = 0x5A, + LWin = 0x5B, + RWin = 0x5C, + Apps = 0x5D, + Sleep = 0x5F, + NumPad0 = 0x60, + NumPad1 = 0x61, + NumPad2 = 0x62, + NumPad3 = 0x63, + NumPad4 = 0x64, + NumPad5 = 0x65, + NumPad6 = 0x66, + NumPad7 = 0x67, + NumPad8 = 0x68, + NumPad9 = 0x69, + Multiply = 0x6A, + Add = 0x6B, + Separator = 0x6C, + Subtract = 0x6D, + Decimal = 0x6E, + Divide = 0x6F, + F1 = 0x70, + F2 = 0x71, + F3 = 0x72, + F4 = 0x73, + F5 = 0x74, + F6 = 0x75, + F7 = 0x76, + F8 = 0x77, + F9 = 0x78, + F10 = 0x79, + F11 = 0x7A, + F12 = 0x7B, + F13 = 0x7C, + F14 = 0x7D, + F15 = 0x7E, + F16 = 0x7F, + F17 = 0x80, + F18 = 0x81, + F19 = 0x82, + F20 = 0x83, + F21 = 0x84, + F22 = 0x85, + F23 = 0x86, + F24 = 0x87, + NumLock = 0x90, + Scroll = 0x91, + LShiftKey = 0xA0, + RShiftKey = 0xA1, + LControlKey = 0xA2, + RControlKey = 0xA3, + LMenu = 0xA4, + RMenu = 0xA5, + BrowserBack = 0xA6, + BrowserForward = 0xA7, + BrowserRefresh = 0xA8, + BrowserStop = 0xA9, + BrowserSearch = 0xAA, + BrowserFavorites = 0xAB, + BrowserHome = 0xAC, + VolumeMute = 0xAD, + VolumeDown = 0xAE, + VolumeUp = 0xAF, + MediaNextTrack = 0xB0, + MediaPreviousTrack = 0xB1, + MediaStop = 0xB2, + MediaPlayPause = 0xB3, + LaunchMail = 0xB4, + SelectMedia = 0xB5, + LaunchApplication1 = 0xB6, + LaunchApplication2 = 0xB7, + OemSemicolon = 0xBA, + Oem1 = OemSemicolon, + Oemplus = 0xBB, + Oemcomma = 0xBC, + OemMinus = 0xBD, + OemPeriod = 0xBE, + OemQuestion = 0xBF, + Oem2 = OemQuestion, + Oemtilde = 0xC0, + Oem3 = Oemtilde, + OemOpenBrackets = 0xDB, + Oem4 = OemOpenBrackets, + OemPipe = 0xDC, + Oem5 = OemPipe, + OemCloseBrackets = 0xDD, + Oem6 = OemCloseBrackets, + OemQuotes = 0xDE, + Oem7 = OemQuotes, + Oem8 = 0xDF, + OemBackslash = 0xE2, + Oem102 = OemBackslash, + ProcessKey = 0xE5, + Packet = 0xE7, + Attn = 0xF6, + Crsel = 0xF7, + Exsel = 0xF8, + EraseEof = 0xF9, + Play = 0xFA, + Zoom = 0xFB, + NoName = 0xFC, + Pa1 = 0xFD, + OemClear = 0xFE, + Shift = 0x00010000, + Control = 0x00020000, + Alt = 0x00040000, + } +} + +#endif \ No newline at end of file diff --git a/Source/SharpDX.RawInput/Message.cs b/Source/SharpDX.RawInput/Message.cs new file mode 100644 index 000000000..815806997 --- /dev/null +++ b/Source/SharpDX.RawInput/Message.cs @@ -0,0 +1,112 @@ +// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if CORECLR + +using System; + +namespace SharpDX.RawInput +{ + /// + /// Replacement of the Message class from Winforms when compiling against CoreCLR. + /// + public struct Message + { + IntPtr hWnd; + int msg; + IntPtr wparam; + IntPtr lparam; + IntPtr result; + + public IntPtr HWnd + { + get { return hWnd; } + set { hWnd = value; } + } + + public int Msg + { + get { return msg; } + set { msg = value; } + } + + public IntPtr WParam + { + get { return wparam; } + set { wparam = value; } + } + + public IntPtr LParam + { + get { return lparam; } + set { lparam = value; } + } + + public IntPtr Result + { + get { return result; } + set { result = value; } + } + + public static Message Create(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) + { + Message m = new Message(); + m.hWnd = hWnd; + m.msg = msg; + m.wparam = wparam; + m.lparam = lparam; + m.result = IntPtr.Zero; + + return m; + } + + public override bool Equals(object o) + { + if (!(o is Message)) + { + return false; + } + + Message m = (Message)o; + return hWnd == m.hWnd && + msg == m.msg && + wparam == m.wparam && + lparam == m.lparam && + result == m.result; + } + + public static bool operator !=(Message a, Message b) + { + return !a.Equals(b); + } + + public static bool operator ==(Message a, Message b) + { + return a.Equals(b); + } + + public override int GetHashCode() + { + return (int)hWnd << 4 | msg; + } + } +} + +#endif \ No newline at end of file diff --git a/Source/SharpDX.RawInput/RegisterDeviceOptions.cs b/Source/SharpDX.RawInput/RegisterDeviceOptions.cs index d08bc20e2..8fa606748 100644 --- a/Source/SharpDX.RawInput/RegisterDeviceOptions.cs +++ b/Source/SharpDX.RawInput/RegisterDeviceOptions.cs @@ -18,7 +18,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#if !CORECLR using System.Windows.Forms; +#endif namespace SharpDX.RawInput { diff --git a/Source/SharpDX.RawInput/SharpDX.RawInput.csproj b/Source/SharpDX.RawInput/SharpDX.RawInput.csproj index a36bab483..8a8f30e3c 100644 --- a/Source/SharpDX.RawInput/SharpDX.RawInput.csproj +++ b/Source/SharpDX.RawInput/SharpDX.RawInput.csproj @@ -37,8 +37,11 @@ + + + diff --git a/Source/Tools/SharpCli/InteropApp.cs b/Source/Tools/SharpCli/InteropApp.cs index 8b796cce0..321e0fbbf 100644 --- a/Source/Tools/SharpCli/InteropApp.cs +++ b/Source/Tools/SharpCli/InteropApp.cs @@ -779,12 +779,18 @@ public bool PatchFile(string file) if(targetFrameworkAttr != null && targetFrameworkAttr.ConstructorArguments.Count > 0 && targetFrameworkAttr.ConstructorArguments[0].Value != null) { + string netcoreAssemblyPath; +#if !CORECLR var targetFramework = new FrameworkName(targetFrameworkAttr.ConstructorArguments[0].Value.ToString()); - var netcoreAssemblyPath = string.Format(@"Reference Assemblies\Microsoft\Framework\{0}\v{1}", + netcoreAssemblyPath = string.Format(@"Reference Assemblies\Microsoft\Framework\{0}\v{1}", targetFramework.Identifier, targetFramework.Version); netcoreAssemblyPath = Path.Combine(ProgramFilesx86(), netcoreAssemblyPath); +#else + // For the time being that path might need to be updated. + netcoreAssemblyPath = ".\\deps\\CoreFX\\CoreCLR\\v5.0\\"; +#endif if(Directory.Exists(netcoreAssemblyPath)) { resolver.AddSearchDirectory(netcoreAssemblyPath); diff --git a/deps/CoreFX b/deps/CoreFX new file mode 160000 index 000000000..00c228f7e --- /dev/null +++ b/deps/CoreFX @@ -0,0 +1 @@ +Subproject commit 00c228f7e217e44afd3031955891e3ef67cf34fe