Skip to content

Commit

Permalink
imp - Graphics card names complete
Browse files Browse the repository at this point in the history
---

We've used array of chars. Now, we have full names of GPUs.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Aug 1, 2024
1 parent 70101cd commit 68c864f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions SpecProbe.Native/Structs/GpuInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal struct GpuInfo
internal int deviceId;

// IntPtr, was WCHAR[128]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal string name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
internal char[] name;
}
}
23 changes: 21 additions & 2 deletions SpecProbe/Probers/VideoProber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace SpecProbe.Probers
{
Expand Down Expand Up @@ -222,12 +223,30 @@ public static BaseHardwarePartInfo[] GetBaseHardwarePartsWindows()
bool result = VideoHelper.GetGpus().Invoke(out IntPtr gpus, out int length);
if (!result)
throw new Exception("Can't parse video cards.");

// Enumerate parsed GPUs
for (int i = 0; i < length - 1; i++)
{
GpuInfo gpuPart = (GpuInfo)Marshal.PtrToStructure(gpus + (264 * i), typeof(GpuInfo));
// Get the GPU part
int size = Marshal.SizeOf(typeof(GpuInfo));
GpuInfo gpuPart = (GpuInfo)Marshal.PtrToStructure(gpus + (size * i), typeof(GpuInfo));

// Build the name
char[] nameChars = gpuPart.name;
StringBuilder builder = new();
for (int c = 0; c < nameChars.Length; c += 2)
{
// Get the character and check for null char
char character = nameChars[c];
if (character == '\0')
break;
builder.Append(character);
}

// Install the part
parts.Add(new VideoPart()
{
VideoCardName = gpuPart.name
VideoCardName = builder.ToString()
});
}
}
Expand Down

0 comments on commit 68c864f

Please sign in to comment.