1

I'm looking for a way to adjust the brightness of a display, which is connected via HDMI to a Dragonboard 410c with Windows IoT Core installed. I read that DCC/CI can control the brightness over HDMI, tested that already with an OpenSource tool called "Monitorian" on my Windows 10 machine, which does work. This tool is written in C# but relies on "DllImport", with which i absolutely have no experience. So the question is, is it possible, to control the brightness from my UWP code somehow?

Using Windows 10 IoT Core API Porting Tool for Monitorian

Parsing Users\Dev\Desktop\mon\Monitorian.exe

Unbehandelte Ausnahme: System.DllNotFoundException: Die DLL "SQLite.Interop.dll": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
   bei System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op)
   bei System.Data.SQLite.SQLite3.StaticIsInitialized()
   bei System.Data.SQLite.SQLiteLog.Initialize()
   bei System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
   bei System.Data.SQLite.SQLiteConnection..ctor(String connectionString)
   bei IoTAPIPortingTool.Program.ProcessLines(String[] lines, Boolean isUAP, String filename, StringBuilder outputBuilder) in C:\Users\Dev\Desktop\iot-utilities-master\IoTAPIPortingTool\Program.cs:Zeile 213.
   bei IoTAPIPortingTool.Program.Main(String[] args) in C:\Users\Dev\Desktop\iot-utilities-master\IoTAPIPortingTool\Program.cs:Zeile 498.
1
  • 2
    Short answer: no. Extended answer: not directly, you will need to rely on native functions in order to access such low-level functions, so you will need to use native interop. Unless you find a third-party library that does all the "nasty stuff" for you you're going to need interop. If you decide to try to do it, this may help you: stackoverflow.com/questions/4013622/… Also, learning how interop works is always a good thing ;)
    – Gusman
    Oct 17, 2020 at 16:10

1 Answer 1

2

Fork Monitorian project, it's in GitHub and already has P/Invoke you're looking for !

Check that out:

https://github.com/emoacht/Monitorian/search?q=dllimport

Brightness functions are readily available:

    [DllImport("Dxva2.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool GetMonitorBrightness(
        SafePhysicalMonitorHandle hMonitor,
        out uint pdwMinimumBrightness,
        out uint pdwCurrentBrightness,
        out uint pdwMaximumBrightness);

    [DllImport("Dxva2.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool SetMonitorBrightness(
        SafePhysicalMonitorHandle hMonitor,
        uint dwNewBrightness);

There should be little changes needed if any for you to re-use the Monitorian.Core project on your application as well.

And as others said, P/Invoke isn't that difficult plus now you have a pretty good example.

Caveat: not sure about the availability of these APIs under UWP however.

Edit:

No support under UWP:

Minimum supported client Windows Vista [desktop apps only]

https://learn.microsoft.com/en-us/windows/win32/api/highlevelmonitorconfigurationapi/nf-highlevelmonitorconfigurationapi-getmonitorbrightness

What about trying the other way around then?

Host WinRT XAML controls in desktop apps (XAML Islands)

Edit:

There isn't a list of what's Win32 supported under IoT but there's a tool instead:

Windows 10 IoT Core API Porting Tool

Windows 10 IoT Core only supports a subset of the Win32 and .NET API surface area available on various prior versions of Windows. This tool will scan your binaries and give you a report of the APIs these binaries use that aren't available and give suggestions for possible replacements. This will both help with estimating the cost of a port to IoT Core as well as help you along the way.

So give it a try and see what it says.

5
  • Thank you for your answer. I wrote a test application with the code from Monitorian, but it seems that there are some permissions needed. I get: Exception thrown: 'System.ComponentModel.Win32Exception' in BrightnessControlTest.exe Windows API threw an error when changing brightness (0x5): Access denied
    – andy
    Oct 19, 2020 at 15:07
  • Thanks for the additional informations. The problem is, that i need it to run on a Dragonboard 410c, so Windows IoT Core is my current playground.
    – andy
    Oct 21, 2020 at 18:21
  • I've added the output in my main question
    – andy
    Oct 22, 2020 at 6:59
  • With the code from monitorian, it is possible to adjust the brightness in a small console application on full Windows 10. But when i compile it for ARM and deploy it in my Dragonboard, it does not work. Debugging seems to show, that the first methode call "EnumDisplayMonitors", does not exist in "User32.dll". This library is also smaller on my Dragonboard / Windows IoT Core, than on a full Windows 10...
    – andy
    Oct 26, 2020 at 17:31
  • 1
    Not sure how to help, maybe you should ask other questions to maximize your chances of getting an answer. Oct 26, 2020 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.