Search code examples
c#c++driveracpi

Is it possible to call ACPI methods from C + + programs?


I hope to call ACPI methods through C++ library in C#, cause I am writing a uwp app for an OEM company, They provide an ACPI method to control the power supply of a USB device. but I seem to find in this link that ACPI methods cannot be called in C++ library(Correct it, I now know it's completely right).

It says: "ACPI methods can only be called from a kernel driver, and then only from the driver stack for the device that the method is declared in the DSDT.”

In addition, i seem to have found some repositories that can call ACPI methods in C# (user mode), such as AcpiTool and WindowsHwAccess(seem to require running in kernel mode, I'm not sure).

Anyway, can I call APCI methods in C#(user mode) through the C++ library imported into the C# project? Or should i say that the C++ library introduced in the C# project can run in kernel mode?


Solution

  • It’s of course possible to call ACPI from C++ if you run said C++ in kernel context or on bare metal (when your code runs directly on the hardware without an operating system as an intermediary). And you certainly could stick a C# runtime into kernel context and thus call ACPI from C#. It has been done: read up on Project Midori, where Windows got reimplemented entirely in managed code. But you’re asking whether you can call ACPI from your C# userland code on Windows. You can’t do it directly but there may be drivers bundled with Windows that expose the information and/or functionality that you’re after. You have a typical XY problem: you think you need ACPI but you didn’t say what for. It’s highly likely that the “what for” part has an answer that doesn’t necessitate writing driver code nor doing direct ACPI calls. Please update your question with a description of what is it that you’re trying to do - forget about ACPI for the time being. If ACPI turns out to be the only way to do it, so be it, but let someone state that in an answer instead of you just going with that assumption.

    TL;DR: You’re probably going about it in a too complicated fashion.