flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > A simple DLL (retrieve basic CPU info) for P/Invoke |
| Author |
|
|
FlierMate11 01 Feb 2023, 13:27
Quote: Discussion on high level language compilers using flat assembler as a backend.... Yes, although it is not the same nature, but I am talking about usage of DLL in high-level language, so I think I will 'advertise' here. Hehe. This DLL returns two information only, processor name string, and AVX support status (taken from Tomasz's code example)
This is how to call the DLL function from C# .NET: (Must set x86 Debug or Release mode, don't use "Any CPU", or else it complains error "BadImageFormatException") Code: using System.Runtime.InteropServices; using System.Text; namespace CheckCpu { public partial class Form1 : Form { [DllImport(@"C:\Users\~User~\Projects\cpuname.dll")] private static extern uint IsAvxSupported(); [DllImport(@"C:\Users\~User~\Projects\cpuname.dll")] private static extern IntPtr GetCpuName(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { if (IsAvxSupported() == 1) label1.Text = "AVX Support: No"; else if (IsAvxSupported() == 2) label1.Text = "AVX Support: Yes"; else label1.Text = "AVX Support: Unknown"; textBox1.Text = Marshal.PtrToStringAnsi(GetCpuName()); } } } Hope someone will benefit from it. I don't know if .NET already has function to check CPU brand name?
Last edited by FlierMate11 on 01 Feb 2023, 20:52; edited 1 time in total |
|||||||||||||||||||||
|
|
sinsi 01 Feb 2023, 20:19
Off topic, but you could use PtrToStringAnsi instead of Marshal.ReadByte
|
|||
|
|
FlierMate11 01 Feb 2023, 20:55
@DimonSoft, nice hearing your story back in university project. You started coding in FASM much earlier than me. I think it is still old version of Windows at that time where DLL source code was not finalized yet by Tomasz.
@sinsi, thanks for the brilliant Marshal.PtrToStringAnsi, just one line of code. I edited the original post to reflect the changes. |
|||
|
|
DimonSoft 03 Feb 2023, 12:03
FlierMate11 wrote: I think it is still old version of Windows at that time where DLL source code was not finalized yet by Tomasz. Not sure I got you right, or you got me right. It was FASM that solved my problem in a few minutes with very few effort. Unlike VS. |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.