https://github.com/rpdevjesco/systemmonitoring
A simple practice application to get better at writing C# wrappers for C++ code.
https://github.com/rpdevjesco/systemmonitoring
Last synced: 8 days ago
JSON representation
A simple practice application to get better at writing C# wrappers for C++ code.
- Host: GitHub
- URL: https://github.com/rpdevjesco/systemmonitoring
- Owner: RPDevJesco
- Created: 2024-07-10T02:07:24.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-10T02:09:57.000Z (about 2 years ago)
- Last Synced: 2025-04-13T03:18:14.882Z (over 1 year ago)
- Language: C++
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# System Information Gatherer
The System Information Gatherer is a cross-platform project that provides comprehensive system information, including CPU, RAM, and GPU details. This project consists of a native C++ DLL and a C# wrapper to facilitate easy integration with .NET applications.
## Features
- Retrieve CPU name, core count, and usage statistics.
- Retrieve operating system information.
- Retrieve total and used RAM.
- Retrieve GPU information.
## Project Structure
- `SystemInfo.hpp`: Header file defining the interface for the system information functions.
- `SystemInfo.cpp`: Implementation of the system information functions for different platforms.
- `SystemInfoWrapper.cs`: C# wrapper to provide access to the system information from .NET applications.
- `Program.cs`: Example .NET console application demonstrating how to use the `SystemInfoWrapper` class.
## Building the Project
### Prerequisites
- CMake
- Visual Studio (for Windows)
- A C++ compiler (e.g., GCC for Linux)
- .NET SDK
### Steps
1. Clone the repository:
```bash
git clone https://github.com/yourusername/SystemInformationGatherer.git
cd SystemInformationGatherer
```
2. Build the native C++ DLL:
On Windows:
```bash
mkdir build
cd build
cmake ..
cmake --build .
```
On Linux:
```bash
mkdir build
cd build
cmake ..
make
```
3. Build the C# wrapper and example application:
```bash
cd ../SystemInfoSharp
dotnet build
```
## Usage
### Using the C++ Library
Include the `SystemInfo.hpp` header in your C++ project and link against the compiled DLL.
### Using the C# Wrapper
Add a reference to the `SystemInfoSharp` project or DLL in your .NET application. Then, use the `SystemInfoWrapper` class to retrieve system information.
Example:
```csharp
using System;
using SystemInfoSharp;
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"CPU Name: {SystemInfoWrapper.CPUName}");
var (physicalCores, logicalCores) = SystemInfoWrapper.CPUCores;
Console.WriteLine($"CPU Cores: {physicalCores} physical, {logicalCores} logical");
Console.WriteLine($"OS Info: {SystemInfoWrapper.OSInfo}");
Console.WriteLine($"Total RAM: {SystemInfoWrapper.TotalRAM:F2} GB");
Console.WriteLine($"Used RAM: {SystemInfoWrapper.UsedRAM:F2} GB");
Console.WriteLine("GPU Info:");
Console.WriteLine(SystemInfoWrapper.GPUInfo);
var (totalCPUUsage, coreUsages) = SystemInfoWrapper.CPUUsage;
Console.WriteLine($"Total CPU Usage: {totalCPUUsage:F2}%");
Console.WriteLine("CPU Core Usages:");
for (int i = 0; i < coreUsages.Length; i++)
{
Console.WriteLine($" Core {i}: {coreUsages[i]:F2}%");
}
}
}
```