• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms & Conditions
Flyy Tech
  • Home
  • Apple
  • Applications
    • Computers
    • Laptop
    • Microsoft
  • Security
  • Smartphone
  • Gaming
  • Entertainment
    • Literature
    • Cooking
    • Fitness
    • lifestyle
    • Music
    • Nature
    • Podcasts
    • Travel
    • Vlogs
  • Camera
  • Audio
No Result
View All Result
  • Home
  • Apple
  • Applications
    • Computers
    • Laptop
    • Microsoft
  • Security
  • Smartphone
  • Gaming
  • Entertainment
    • Literature
    • Cooking
    • Fitness
    • lifestyle
    • Music
    • Nature
    • Podcasts
    • Travel
    • Vlogs
  • Camera
  • Audio
No Result
View All Result
Flyy Tech
No Result
View All Result

Using Open Hardware Monitor Source Code DLL With C#

flyytech by flyytech
September 2, 2022
Home Computers
Share on FacebookShare on Twitter


Did you know that the Open Hardware Monitor DLL provided with HWMonitor (OpenHardwareMonitorLib.dll) handles all of the heavy lifting within the application and can be used by developers to power C#/.NET/ASP projects with relative ease.

You can simply copy this single file, drop it into your c# project, add a reference and you can start creating system health applications in a few simple steps.

Open Hardware Monitor DLL with Visual Studio
Open Hardware Monitor DLL with Visual Studio

Before we get started, let me introduce myself; I’m Andy, and I shall be your host for the next ten minutes. If you like, you can follow me on Twitter where I post about my journey as a technology writer and a freelance designer & developer.

You might like: Huge List of Free Overclocking Software

First up, What is HWMonitor?

CPUID HWMonitor Program
HWMonitor by CPUID

To first understand the Open Hardware Monitor Libray, you first must understand what HWMonitor does. HWMonitor is a system information & system health monitoring software for Windows and Linux. This free system reporting software displays information on a wide range of your computer hardware sensors such as CPU, RAM, GPU, Fans, hard drives and even motherboard.

This application is popular amongst overclockers, gamers, computer hardware enthusiasts, professional computer technicians and, comes with several features that put it a step ahead of the competition for its reporting capabilities.

HWMonitor Key Features

  • Trusted within the community
  • Support for AMD, Via & Intel Processors
  • Support for AMD, ATI & Nvidia GPUs
  • Can report frequencies, voltages, temperature and more.
  • Constantly updated with fresh hardware support
  • Pro version includes additional logging capabilities, remote operation, and graphing. (Not required for this article)

At the core, HWMonitor is getting all of its data from the OpenHardwareMonitorLib.dll which is included within the directory of the downloaded files. This single file is responsible for all of the system health statistics and system information reported within the program – lucky for us, we can take the DLL and use it in our own projects.

HWMonitor is available for everyone to download from the CPUID download page with no strings attached.

What System Information can I access using OpenHardwareMonitorLib.dll?

Now that you understand HWMonitor and what its purpose is, you might be left with a question: what can you do with the Open Hardware Monitor DLL, and what information does it expose? Here is everything I could find.

# Hardware Information Available
1 CPU Bus Speed, Frequency, Usage, Temperature, Power Draw
2 GPU Core Frequency, Memory Frequency, GPU Usage, Temperature
3 RAM Ram usage
4 Motherboard Vcore, DRAM voltage, System Temperature, CPU Temperature
5 Hard Drives S.M.A.R.T, SSD Wear Level, Read/Write
6 Fans Fan Speed

For this article, I will be focusing on fetching the CPU and GPU information, storing them in variables and outputting the values to the console. If you need more stats such as motherboard or ram, you can use the same methods to access any other system information you wish.

Integrating the HWMonitor DLL with Visual Studio / C#

Before you can query the DLL and start fetching information in your C# code, you need to go through some basic project set up to ensure you can access Open Hardware Monitor from within your project.

Below is an overview of the steps required.

Steps Required

  1. Download Visual Studio
  2. Open Visual Studio
  3. Start a New C# Project
  4. Extract OpenHardwareMonitorLib.dll
  5. Add DLL to Visual Studio Project
  6. Force your app to run in administrator mode

Shall we get started?

1. Download Visual Studio

Head over to the Visual Studio website and download the relevant version. I am using MAC for programming atm so I downloaded that one.

2. Install & Open Visual Studio

Start a new projectt
Open Visual Studio

Once you have downloaded Visual Studio, go ahead and open the file to start the installation. Once complete go ahead and open the program.

3. Start a New C# Project

Before you can start writing any code or interacting with HWMonitor, you need to set up a new project.

Follow these simple steps to get started:

  1. Click new
  2. Select console project
  3. After, select .net framework 5.0
  4. Give your project a unique name
  5. Enable GIT if you need version control
  6. Click the create button
HWMonitor DLL
Start a new project

With your C# project set up and ready to go, you need to extract the required file and pull it into your project. To do this, download HWMonitor, open the zip and move OpenHardwareMonitorLib.dll into your new c# project folder.

5. Add DLL to Visual Studio Project

HWmonitor c# reference
Reference the Open Hardware Monitor DLL

To start fetching the system information in our code, you need to add the DLL file reference to your visual studio c# project.

Here is what you need to do:

  1. Click Project > Add Reference
  2. Select the .net assembly tab, click Browse
  3. Navigate to and select the copy of OpenHardwareMonitorLib.dll that you placed in your project folder
  4. Hit ok

These critical steps ensure you have added the required DLL file to the project and that you can now reference it in your project’s files. To find out how to probe your system and pull essential information such as CPU frequency, load and voltage, move on to the next step below, which outlines some practical examples.

6. Force your app to run in administrator mode

To access system-level information, you need to complete one final step designed to enable administrator access at startup.

  1. From the project panel, right click Project > Add New and click Application Manifest File
  2. Press Ctrl + Shift + F and search for “requestedExecutionLevel”
  3. Change the tag to:

Failure to complete these final steps will result in blank data being returned from OpenHardwareMonitorLib.dll. Unfortunately, I made this mistake in my project and spent ages debugging.

Example Code: OpenHardwareMonitorLib.dll and C#

The above example will get you up and going with an actual application that grabs information about your computer’s CPU and GPU and outputs them to a simple console app. If you want, you can grab this code via the Gist.

Before you can use this example code, you will need to set up a new project which I outlined in the previous step.

Breaking down the Code

Open Hardware Monitor code breakdown

The above code is an excellent copy and paste example for experienced developers who know their way around but, for those of you with a little less programming experience, this section was made for you.

I will break down the example code and show you step by step how everything is working.

1. Include a Reference to the DLL

To start and, before you can access the hardware reports you need, you will first need to include a reference to the DLL at the top of your project main file right after the other using statements.

This line of code will enable Visual Studio to access the functionality we need in further steps. Let us move on.

2. Defining the Hardware to Report

To start grabbing pc health stats, we need to define a new computer object exposed by the Open Hardware Monitor DLL. Everything we need is held within the computer object, and it is also where we define which hardware we want pc health stats reported for.

You will notice two settings within our new computer object; GPUEnabled = true and CPUEnabled = true. These settings tell the Open Hardware Monitor library to return data for any processors or graphics cards currently connected to the system. If we don’t define them here, we won’t have any data within the loop.

In case you are wondering, here is a list of the options available to the object: new Computer(){}.

Full List of Hardware Reports Available

  1. GPUEnabled – Enable GPU related statistics and reports
  2. CPUEnabled – Enable CPU related statistics and reports
  3. RAMEnabled – Enable RAM related statistics and reports
  4. MainboardEnabled – Enable Motherboard related statistics and reports
  5. FanControllerEnabled – Enable Fan related statistics and reports
  6. HDDEnabled – Enable Hard Drive related statistics and reports

Now, considering we have defined the computer object, we need to start a connection between your code and the DLL file.

This single line will startup the DLL and enable it to start fetching pc health status.

3. The Loop

The loop is where the magic happens and is called every second by the Main method located at the bottom of the file. This loop makes a call to ReportSystemInfo(), which goes through all the available data and returns only the information we have requested.

As you can see, methods are relatively straight forward and it’s as simple as targeting the correct Sensor Type and Sensor Name.

4. Accessing CPU Information

Inside the loop, there are two distinct sections covering CPU information and the other covering the GPU. Here we will look specifically at the CPU.

5. Accessing GPU Information

After the CPU section, you will find one more section covering system information for both Nvidia and AMD GPUs. The Open Hardware Monitor library reports information for both separately, so we need to access them in their unique way.

Conclusion

This has been quite a lengthy tutorial. If you followed along and managed to get everything working, pat yourself on the back.

The Open Hardware Library enables .net and c# developers to interface with system hardware and fetch key information on a range of hardware sensors. This method could pave the way for unique applications that are decoupled from the HWMonitor UI. This will enable developers such as yourself to easily create their system health monitors and pc health status monitors.





Source_link

flyytech

flyytech

Next Post
Samsung Galaxy S22 Ultra review

Samsung Galaxy S22 Ultra review

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Chinese GPU Dev Starts Global Sales of $245 RTX 3060 Ti Rival

China-Made Moore Thread GPU Can’t Match RTX 3060

November 18, 2022
Universal Audio releases Volt 4 and Volt 476P USB-C I/Os

Universal Audio releases Volt 4 and Volt 476P USB-C I/Os

September 8, 2022

Trending.

Image Creator now live in select countries for Microsoft Bing and coming soon in Microsoft Edge

Image Creator now live in select countries for Microsoft Bing and coming soon in Microsoft Edge

October 23, 2022
Elden Ring best spells 1.08: Tier lists, sorceries, incantations, and locations

Elden Ring best spells 1.08: Tier lists, sorceries, incantations, and locations

January 14, 2023
How to View Ring Doorbell on a Roku TV

How to View Ring Doorbell on a Roku TV

December 20, 2022
Allen Parr’s false teaching examined. Why you should unfollow him.

Allen Parr’s false teaching examined. Why you should unfollow him.

September 24, 2022
Review: Zoom ZPC-1

Review: Zoom ZPC-1

January 28, 2023

Flyy Tech

Welcome to Flyy Tech The goal of Flyy Tech is to give you the absolute best news sources for any topic! Our topics are carefully curated and constantly updated as we know the web moves fast so we try to as well.

Follow Us

Categories

  • Apple
  • Applications
  • Audio
  • Camera
  • Computers
  • Cooking
  • Entertainment
  • Fitness
  • Gaming
  • Laptop
  • lifestyle
  • Literature
  • Microsoft
  • Music
  • Podcasts
  • Review
  • Security
  • Smartphone
  • Travel
  • Uncategorized
  • Vlogs

Site Links

  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms & Conditions

Recent News

New Android Banking Trojan ‘Nexus’ Promoted As MaaS

New Android Banking Trojan ‘Nexus’ Promoted As MaaS

March 23, 2023
Could we Get a OnePlus 11 Special Edition Soon? – Phandroid

Could we Get a OnePlus 11 Special Edition Soon? – Phandroid

March 23, 2023

Copyright © 2022 Flyytech.com | All Rights Reserved.

No Result
View All Result
  • Home
  • Apple
  • Applications
    • Computers
    • Laptop
    • Microsoft
  • Security
  • Smartphone
  • Gaming
  • Entertainment
    • Literature
    • Cooking
    • Fitness
    • lifestyle
    • Music
    • Nature
    • Podcasts
    • Travel
    • Vlogs

Copyright © 2022 Flyytech.com | All Rights Reserved.

What Are Cookies
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT