Keep the light on

  • Thread starter Thread starter cyberco
  • Start date Start date
Thanks, Peter, that seems to do what I'm after. Unfortunately I'm
completely new to VB and I'm not sure I'm translating the DLL imports
correctly to C#. Do you know if there is a C# example of this code
somewhere? I found this as well, but that doesn't talk about backlight
issues:
http://www.pcreview.co.uk/forums/thread-2299260.php

====== VB ==================================
Private Declare Function SetPowerRequirement Lib "coredll.dll" (ByVal
pvDevice As String, ByVal DeviceState As PowerState, ByVal DeviceFlags
As Integer, ByVal pvSystemState As IntPtr, ByVal StateFlags As Integer)
As IntPtr

Private Declare Function ReleasePowerRequirement Lib "coredll.dll"
(ByVal handle As IntPtr) As Integer
==================================

translated to C#

==== C# ==================================
[DllImport("coredll.dll", SetLastError = true)]
internal extern static int SetPowerRequirement(string pvDevice,
DevicePowerState deviceState, int deviceFlags, ref ??? systemState, int
StateFlags);

[DllImport("coredll.dll", SetLastError = true)]
internal extern static int ReleasePowerRequirement(???);
=========================================

The '???' mark where I got lost :)
Any suggestions?
 
Thanks! I ended up with the following import statements:

==== C# ==================================
[DllImport("coredll.dll", SetLastError = true)]
internal extern static IntPtr SetPowerRequirement(string pvDevice,
DevicePowerState deviceState, int deviceFlags, IntPtr systemState, int
StateFlags);

[DllImport("coredll.dll", SetLastError = true)]
internal extern static int ReleasePowerRequirement(IntPtr handle);
=========================================

You can invoking this from within your C# code as follows:

==== C# ==================================
private static IntPtr handle;

public static void keepBackLightOn() {
handle = NativeMethods.SetPowerRequirement("BKL1:",
DevicePowerState.D0, 1, System.IntPtr.Zero,
}

public static void restoreBackLightSetting() {
if (handle.ToInt32() != 0) {
int result;
result = NativeMethods.ReleasePowerRequirement(handle);
handle = IntPtr.Zero;
}
}
=========================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top