Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
102c126
Removed specification of TargetFrameworkProfile and TargetFrameworkVe…
Aug 24, 2015
2d095f1
Fixed wrong style comment.
Sep 1, 2015
9b6059c
Merge remote-tracking branch 'origin' into coreclr
Sep 17, 2015
c83247b
Added Corefxref submodule as CoreFX in new `deps' directory. This wil…
Sep 25, 2015
764c8d7
Updated to VS 2015.
Sep 25, 2015
5954980
CoreCLR support: replaced HandleRef by IntPtr in Pinvoke routines as …
Sep 25, 2015
1caf545
Merge remote-tracking branch 'origin/master' into coreclr
Sep 25, 2015
5e19c11
Merge remote-tracking branch 'manu/coreclr' into coreclr
Sep 25, 2015
c5252ec
Added support for CoreCLR compilation. For now only the desktop side …
Sep 25, 2015
537a389
Made SharpDX.RawInput compile against CoreCLR. The main issue is in D…
Sep 25, 2015
e29a5ed
Excluded some files from CoreCLR compilation in SharpDX.MediaFoundati…
Sep 25, 2015
882a278
Made code compile for CoreCLR by using extension methode GetSafeWaitH…
Sep 25, 2015
8907335
Update to new Reflection API that works equally well under both the .…
Sep 25, 2015
62134c8
Made code compile for CoreCLR by using extension methode GetSafeWaitH…
Sep 25, 2015
c4781f3
In CoreCLR there is no Windows API to retrieve MainWindowHandle, so f…
Sep 25, 2015
bb74bbc
In CoreCLR there is no Environment.Is64BitProcess, so we created our …
Sep 25, 2015
33f302a
Made code compiled against CoreCLR by excluding some portion of code …
Sep 25, 2015
2fac923
Excluded string.Intern when compiling against CoreCLR since this is n…
Sep 25, 2015
1213665
Updated SharpCli to use our CoreCLR assemblies. The path is relative …
Sep 25, 2015
600dd35
Updated to the latest CoreFX reference assemblies.
Oct 15, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion Build/SharpDX.PreSettings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<SharpDXSign Condition=" '$(SharpDXSign)' == '' ">false</SharpDXSign>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SharpDXPlatform Condition="'$(SharpDXPlatform)' == ''">Desktop</SharpDXPlatform>
<SharpDXRuntime Condition="'$(SharpDXRuntime)' == ''">CoreCLR</SharpDXRuntime>

<!--Set defaults for all win8/directx11.1 features-->
<SharpDXDesktopOnly Condition="'$(SharpDXDesktopOnly)' == ''">false</SharpDXDesktopOnly>
Expand All @@ -37,16 +38,26 @@

<!--.NET 4.5 - Desktop - PCL Net45 -->
<PropertyGroup Condition="'$(SharpDXPlatform)|$(SharpDXDesktopOnly)' == 'Desktop|false'">
<!-- This part is for compiling against the PCL for .NET 4.5.
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<SharpDXCSharpTargets>$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets</SharpDXCSharpTargets>
-->
<TargetFrameworkRootPath>$(SolutionDir)\deps\CoreFX</TargetFrameworkRootPath>
<FrameworkPathOverride>$(SolutionDir)\deps\CoreFX\CoreCLR\v5.0</FrameworkPathOverride>
<SharpDXCSharpTargets>$(SolutionDir)\deps\CoreFX\configs\CoreCLR.CSharp.targets</SharpDXCSharpTargets>
</PropertyGroup>

<!--.NET 4.5 - PCL or Win81/WP81 StoreApp -->
<PropertyGroup Condition="'$(SharpDXPlatform)' == 'StoreApp'">
<TargetFrameworkProfile>Profile32</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<SharpDXCSharpTargets>$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets</SharpDXCSharpTargets>
<!-- This part is for compiling against CoreCLR.
<TargetFrameworkRootPath>$(SolutionDir)\deps\CoreFX</TargetFrameworkRootPath>
<FrameworkPathOverride>$(SolutionDir)\deps\CoreFX\CoreCLR\v5.0</FrameworkPathOverride>
<SharpDXCSharpTargets>$(SolutionDir)\deps\CoreFX\configs\CoreCLR.CSharp.targets</SharpDXCSharpTargets>
-->
</PropertyGroup>

<!--<Import Condition="'$(SharpDXWP8)' != 'false'" Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />-->
Expand Down Expand Up @@ -91,6 +102,10 @@
<DefineConstants>$(DefineConstants);DESKTOP_APP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(SharpDXRuntime)' == 'CoreCLR'">
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(SharpDXPlatform)' == 'StoreApp'">
<DefineConstants>$(DefineConstants);STORE_APP;WINDOWS_API_SET</DefineConstants>
</PropertyGroup>
Expand All @@ -107,4 +122,4 @@
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>

</Project>
</Project>
4 changes: 2 additions & 2 deletions SharpDX-Desktop.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 14 additions & 5 deletions Source/SharpDX.Desktop/MessageFilterHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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
}
}
}
5 changes: 4 additions & 1 deletion Source/SharpDX.Desktop/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Source/SharpDX.Desktop/RenderForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* THE SOFTWARE.
*/

#if !CORECLR
using System.Diagnostics;
using SharpDX.Mathematics.Interop;
using System;
Expand Down Expand Up @@ -448,4 +449,5 @@ protected override bool ProcessDialogKey(Keys keyData)
return base.ProcessDialogKey(keyData);
}
}
}
}
#endif
40 changes: 40 additions & 0 deletions Source/SharpDX.Desktop/RenderLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <summary>
/// Interface to mimic the System.Windows.Forms.Control class to minimize the amount
/// of code to change when not using System.Windows.Forms.
/// </summary>
public interface Control
{
/// <summary>
/// Access to the underlying Win32 HWND handle.
/// </summary>
IntPtr Handle { get; }

/// <summary>
/// Indicates whether the control has been disposed.
/// </summary>
bool IsDisposed { get; }

/// <summary>
/// Show form.
/// </summary>
void Show();

/// <summary>
/// Adds a event handler to listen to the Disposed event on the component.
/// </summary>
event EventHandler Disposed;
}
#endif

/// <summary>
/// RenderLoop provides a rendering loop infrastructure. See remarks for usage.
/// </summary>
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand Down Expand Up @@ -186,13 +224,15 @@ public void Dispose()
/// </summary>
public delegate void RenderCallback();

#if !CORECLR
/// <summary>
/// Runs the specified main loop in the specified context.
/// </summary>
public static void Run(ApplicationContext context, RenderCallback renderCallback)
{
Run(context.MainForm, renderCallback);
}
#endif

/// <summary>
/// Runs the specified main loop for the specified windows form.
Expand Down
8 changes: 6 additions & 2 deletions Source/SharpDX.Desktop/SharpDX.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="RenderControl.cs">
<Compile Condition="'$(SharpDXRuntime)' != 'CoreCLR'" Include="RenderControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="RenderForm.cs">
<Compile Condition="'$(SharpDXRuntime)' != 'CoreCLR'" Include="RenderForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RenderLoop.cs" />
Expand All @@ -46,6 +46,10 @@
<None Include="Documentation\CodeComments.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpDX.RawInput\SharpDX.RawInput.csproj">
<Project>{05d17a7b-f200-48c0-b8f9-b7211665a17f}</Project>
<Name>SharpDX.RawInput</Name>
</ProjectReference>
<ProjectReference Include="..\SharpDX\SharpDX.csproj">
<Project>{d0bcd56a-41c4-4a4e-8590-26864ced07ff}</Project>
<Name>SharpDX</Name>
Expand Down
27 changes: 14 additions & 13 deletions Source/SharpDX.Desktop/Win32Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions Source/SharpDX.Direct3D9/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System;
using System.Globalization;
using System.Reflection;
using SharpDX.Mathematics.Interop;

namespace SharpDX.Direct3D9
Expand Down Expand Up @@ -628,7 +629,7 @@ public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectan
}


/// <summary>
#if !CORECLR
/// Presents the contents of the next buffer in the sequence of back buffers to the screen.
/// </summary>
/// <param name="sourceRectangle">The area of the back buffer that should be presented.</param>
Expand All @@ -647,6 +648,7 @@ public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectan
Present(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, regionPtr);
}
}
#endif

/// <summary>
/// Resets the stream source frequency by setting the frequency to 1.
Expand Down Expand Up @@ -944,7 +946,7 @@ public void SetRenderState(RenderState renderState, float value)
/// <unmanaged>HRESULT IDirect3DDevice9::SetRenderState([In] D3DRENDERSTATETYPE State,[In] unsigned int Value)</unmanaged>
public void SetRenderState<T>(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));
Expand Down
Loading