Files
bluflame/intromat/Intromat/Graphics/DebugInterface.cs
2026-04-18 22:31:51 +02:00

52 lines
1.8 KiB
C#

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Intromat.DXExt;
using SharpDX;
namespace Intromat.Graphics
{
internal static class DebugInterface
{
[Flags]
public enum LoadLibraryFlags : uint
{
LoadLibrarySearchSystem32 = 0x00000800
}
private static readonly GetDebugInterface? getDebugInterface;
static DebugInterface()
{
var moduleHandle = LoadLibraryEx("dxgi.dll", IntPtr.Zero, LoadLibraryFlags.LoadLibrarySearchSystem32);
if (moduleHandle != IntPtr.Zero)
{
var procedureHandle = GetProcAddress(moduleHandle, "DXGIGetDebugInterface1");
if (procedureHandle != IntPtr.Zero)
getDebugInterface = (GetDebugInterface)Marshal.GetDelegateForFunctionPointer(procedureHandle, typeof(GetDebugInterface));
}
}
public static GraphicsAnalysis? TryCreateGraphicsAnalysis()
{
if (getDebugInterface == null)
return null;
var guid = typeof(GraphicsAnalysis).GetTypeInfo().GUID;
var result = getDebugInterface(0, ref guid, out var comPtr);
if (result.Failure)
return null;
return comPtr != IntPtr.Zero ? (GraphicsAnalysis)comPtr : null;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate Result GetDebugInterface(uint flags, ref Guid guid, out IntPtr result);
}
}