From 102c126bc17749f46ec351856617738a83e30e37 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Sun, 23 Aug 2015 22:22:55 -0700 Subject: [PATCH 01/17] Removed specification of TargetFrameworkProfile and TargetFrameworkVersion since we should use the one defined in SharpDX.PreSettings.targets. --- .../SharpDX.MediaFoundation/SharpDX.MediaFoundation.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/SharpDX.MediaFoundation/SharpDX.MediaFoundation.csproj b/Source/SharpDX.MediaFoundation/SharpDX.MediaFoundation.csproj index 103f71ef5..7feb78fef 100644 --- a/Source/SharpDX.MediaFoundation/SharpDX.MediaFoundation.csproj +++ b/Source/SharpDX.MediaFoundation/SharpDX.MediaFoundation.csproj @@ -8,10 +8,6 @@ SharpDX.MediaFoundation SharpDX.MediaFoundation - - Profile32 - v4.6 - @@ -99,4 +95,4 @@ --> - \ No newline at end of file + From 2d095f182dbd95aba2e2ad786f420109b50d2ed4 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Tue, 1 Sep 2015 13:28:28 -0700 Subject: [PATCH 02/17] Fixed wrong style comment. --- Source/SharpDX/Text/ASCIIEncoding.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SharpDX/Text/ASCIIEncoding.cs b/Source/SharpDX/Text/ASCIIEncoding.cs index 54dbc6623..741f42c21 100644 --- a/Source/SharpDX/Text/ASCIIEncoding.cs +++ b/Source/SharpDX/Text/ASCIIEncoding.cs @@ -26,7 +26,7 @@ public abstract class Encoding : System.Text.Encoding { /// /// Returns an encoding for the ASCII character set. The returned encoding - // will be an instance of the ASCIIEncoding class. + /// will be an instance of the ASCIIEncoding class. /// public static readonly ASCIIEncoding ASCII = new ASCIIEncoding(); } From c83247b57c3d8dfdf459dbaddc80cabfe2dcf32f Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 11:46:54 +0900 Subject: [PATCH 03/17] Added Corefxref submodule as CoreFX in new `deps' directory. This will be used to compile SharpFX against CoreCLR. --- .gitmodules | 3 +++ deps/CoreFX | 1 + 2 files changed, 4 insertions(+) create mode 160000 deps/CoreFX 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/deps/CoreFX b/deps/CoreFX new file mode 160000 index 000000000..be60e2cae --- /dev/null +++ b/deps/CoreFX @@ -0,0 +1 @@ +Subproject commit be60e2caeb15fdeb45b282b3cc1da12f9837ae33 From 764c8d7bfaafed7c6b7cd52dabdd76ea54b67b43 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 11:52:44 +0900 Subject: [PATCH 04/17] Updated to VS 2015. --- SharpDX-Desktop.sln | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 5954980806b113bb88e069ce0cf60ce859ca3106 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 15:29:44 +0900 Subject: [PATCH 05/17] CoreCLR support: replaced HandleRef by IntPtr in Pinvoke routines as HandleRef is not present in CoreCLR/CoreFX. --- Source/SharpDX.Desktop/MessageFilterHook.cs | 8 +++--- Source/SharpDX.Desktop/Win32Native.cs | 27 +++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Source/SharpDX.Desktop/MessageFilterHook.cs b/Source/SharpDX.Desktop/MessageFilterHook.cs index c3b08c630..0e49937ca 100644 --- a/Source/SharpDX.Desktop/MessageFilterHook.cs +++ b/Source/SharpDX.Desktop/MessageFilterHook.cs @@ -61,14 +61,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 +149,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); } } 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); From c5252ec40316f030d24d69c94de294e1b4d7b00d Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:00:29 +0900 Subject: [PATCH 06/17] Added support for CoreCLR compilation. For now only the desktop side is compiled by default using CoreCLR. --- Build/SharpDX.PreSettings.targets | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 + From 537a389a7831ec2953960bd30d1ec80f1ddfc626 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:05:43 +0900 Subject: [PATCH 07/17] Made SharpDX.RawInput compile against CoreCLR. The main issue is in Device.cs where we do not have access to the Winform Application class, so we cannot use it. We also add to define our own version of IMessageFilter, Keys and Message normally define in Winforms. --- Source/SharpDX.RawInput/Device.cs | 6 + Source/SharpDX.RawInput/IMessageFilter.cs | 34 +++ .../KeyboardInputEventArgs.cs | 3 + Source/SharpDX.RawInput/Keys.cs | 226 ++++++++++++++++++ Source/SharpDX.RawInput/Message.cs | 112 +++++++++ .../SharpDX.RawInput/RegisterDeviceOptions.cs | 2 + .../SharpDX.RawInput/SharpDX.RawInput.csproj | 3 + 7 files changed, 386 insertions(+) create mode 100644 Source/SharpDX.RawInput/IMessageFilter.cs create mode 100644 Source/SharpDX.RawInput/Keys.cs create mode 100644 Source/SharpDX.RawInput/Message.cs 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 @@ + + + From e29a5ed548ecf63410ac02e6313ca53b0b742c79 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:06:50 +0900 Subject: [PATCH 08/17] Excluded some files from CoreCLR compilation in SharpDX.MediaFoundation. This is while we find a solution for implementing them in CoreCLR if we need it one day. --- Source/SharpDX.MediaFoundation/AudioDecoder.cs | 4 ++-- Source/SharpDX.MediaFoundation/ByteStream.cs | 4 ++-- Source/SharpDX.MediaFoundation/SourceReader.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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. /// From 882a2783a820b71b84b22547ba505eb1b4d8a318 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:13:19 +0900 Subject: [PATCH 09/17] Made code compile for CoreCLR by using extension methode GetSafeWaitHandle instead of SafeWaitHandle. Unfortunately the extension method is only available in .NET Framework 4.6 so we still have to keep the old way of accessing SafeWaitHandle. --- Source/SharpDX.DirectSound/NotificationPosition.cs | 4 ++++ 1 file changed, 4 insertions(+) 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 From 8907335f5ef95a25f9de0726316ff230e060c458 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:15:55 +0900 Subject: [PATCH 10/17] Update to new Reflection API that works equally well under both the .NET Framework and CoreCLR. --- .../Properties/Resources.Designer.cs | 5 ++++- Source/SharpDX.Direct3D9/Device.cs | 3 ++- Source/SharpDX.DirectInput/CustomDevice.cs | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) 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.Direct3D9/Device.cs b/Source/SharpDX.Direct3D9/Device.cs index 580c185d4..e28077a5b 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 @@ -944,7 +945,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.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 From 62134c84ad008a70fe8e9232790c8884b4a8b788 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:16:50 +0900 Subject: [PATCH 11/17] Made code compile for CoreCLR by using extension methode GetSafeWaitHandle instead of SafeWaitHandle. Unfortunately the extension method is only available in .NET Framework 4.6 so we still have to keep the old way of accessing SafeWaitHandle. --- Source/SharpDX.DirectInput/Device.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/SharpDX.DirectInput/Device.cs b/Source/SharpDX.DirectInput/Device.cs index f72a6c733..c8ac69db0 100644 --- a/Source/SharpDX.DirectInput/Device.cs +++ b/Source/SharpDX.DirectInput/Device.cs @@ -273,7 +273,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 } /// From c4781f34f6f5843caa01f8c6b9757a40b333113d Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:20:29 +0900 Subject: [PATCH 12/17] In CoreCLR there is no Windows API to retrieve MainWindowHandle, so for the time being we will assume that the argument is a valid handle of a Window in CoreCLR. --- Source/SharpDX.Desktop/MessageFilterHook.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/SharpDX.Desktop/MessageFilterHook.cs b/Source/SharpDX.Desktop/MessageFilterHook.cs index 0e49937ca..74532fc7d 100644 --- a/Source/SharpDX.Desktop/MessageFilterHook.cs +++ b/Source/SharpDX.Desktop/MessageFilterHook.cs @@ -177,7 +177,12 @@ 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 From bb74bbcbe8a1db40f41daef06cc66508ed73dacc Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:22:17 +0900 Subject: [PATCH 13/17] In CoreCLR there is no Environment.Is64BitProcess, so we created our own Is64BitProcess routine and are using it regardless of being running under the .NET Framework or CoreCLR. --- Source/SharpDX.DirectComposition/DesktopDevice.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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); + } } } From 33f302afae0dc9595c3e8edd8d465f7f341513b5 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:24:01 +0900 Subject: [PATCH 14/17] Made code compiled against CoreCLR by excluding some portion of code that are meaningful only when running under Winforms. --- Source/SharpDX.Desktop/MessageFilterHook.cs | 6 ++- Source/SharpDX.Desktop/RenderForm.cs | 4 +- Source/SharpDX.Desktop/RenderLoop.cs | 40 +++++++++++++++++++ Source/SharpDX.Desktop/SharpDX.Desktop.csproj | 8 +++- Source/SharpDX.Direct3D9/Device.cs | 3 +- Source/SharpDX.Direct3D9/DeviceEx.cs | 5 ++- Source/SharpDX.Direct3D9/Font.cs | 2 + Source/SharpDX.Direct3D9/SwapChain.cs | 3 +- Source/SharpDX.DirectInput/Device.cs | 12 +++++- 9 files changed, 75 insertions(+), 8 deletions(-) diff --git a/Source/SharpDX.Desktop/MessageFilterHook.cs b/Source/SharpDX.Desktop/MessageFilterHook.cs index 74532fc7d..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 @@ -187,4 +191,4 @@ private static IntPtr GetSafeWindowHandle(IntPtr hwnd) #endregion } -} \ No newline at end of file +} 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.Direct3D9/Device.cs b/Source/SharpDX.Direct3D9/Device.cs index e28077a5b..4569ef961 100644 --- a/Source/SharpDX.Direct3D9/Device.cs +++ b/Source/SharpDX.Direct3D9/Device.cs @@ -629,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. @@ -648,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. 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/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.DirectInput/Device.cs b/Source/SharpDX.DirectInput/Device.cs index c8ac69db0..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. /// From 2fac92322d1f84349a8e21bf67ca3da08d521240 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:24:30 +0900 Subject: [PATCH 15/17] Excluded string.Intern when compiling against CoreCLR since this is not available. --- Source/SharpDX.Direct3D9/EffectHandle.cs | 2 ++ 1 file changed, 2 insertions(+) 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)) From 12136651852994eef38b004a5ce971daef6e2ea9 Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Fri, 25 Sep 2015 16:25:31 +0900 Subject: [PATCH 16/17] Updated SharpCli to use our CoreCLR assemblies. The path is relative and it might require hand modification to run against someone's checkout. --- Source/Tools/SharpCli/InteropApp.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); From 600dd357206e6efb0c901bfe1c858bb494c5b72d Mon Sep 17 00:00:00 2001 From: Emmanuel Stapf Date: Thu, 15 Oct 2015 09:35:44 +0900 Subject: [PATCH 17/17] Updated to the latest CoreFX reference assemblies. --- deps/CoreFX | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/CoreFX b/deps/CoreFX index be60e2cae..00c228f7e 160000 --- a/deps/CoreFX +++ b/deps/CoreFX @@ -1 +1 @@ -Subproject commit be60e2caeb15fdeb45b282b3cc1da12f9837ae33 +Subproject commit 00c228f7e217e44afd3031955891e3ef67cf34fe