javajna

how to call CallNtPowerInformation from java jna to get screen display timeout


I am trying to get the information about the time after which windows shutdown the laptop screen after going into idle.

I tried the following code but I have little experience with jna and the structure results are always 0:

    WinNT.SYSTEM_POWER_POLICY systemPowerPolicy= new WinNT.SYSTEM_POWER_POLICY();
    Pointer pointer=systemPowerPolicy.getPointer();
    PowrProf.INSTANCE.CallNtPowerInformation(PowrProf.POWER_INFORMATION_LEVEL.SystemPowerPolicyCurrent,
            Pointer.NULL,0, pointer, systemPowerPolicy.size());
    System.out.println(systemPowerPolicy.VideoDimDisplay);
    System.out.println(systemPowerPolicy.VideoTimeout);

I believe I am not calling the function properly, can you help out in calling this function?

Regards


Solution

  •     int size = new WinNT.SYSTEM_POWER_POLICY().size();
        Memory mem = new Memory(size);
        PowrProf.INSTANCE
                .CallNtPowerInformation(PowrProf.POWER_INFORMATION_LEVEL.SystemPowerPolicyCurrent, null, 0, mem, size);
        WinNT.SYSTEM_POWER_POLICY powerPolicy = new WinNT.SYSTEM_POWER_POLICY(mem);
    
        System.out.println(powerPolicy.VideoTimeout);