Skip to content

Commit

Permalink
BackLightControl: Add new HidKbdData class and additional code to sup…
Browse files Browse the repository at this point in the history
…port updated Keyboard_Core.dll
  • Loading branch information
JooJooBee666 committed Jan 3, 2021
1 parent 2da83af commit 286ac72
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 150 deletions.
Binary file added Installer.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions LBCService/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
</configuration>
42 changes: 38 additions & 4 deletions LBCService/BacklightControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@

namespace LBCService
{
public class HidKbdData
{
public string strProductId;
public string strVendorId;
public string GetHidUsagePage;
public string GetHidUsage;
public string SetHidUsagePage;
public string SetHidUsage;
}

public class BacklightControls
{
public void ActivateBacklight(int lightValue)
{
FileVersionInfo kbcver = null;
if (System.IO.File.Exists(LenovoBacklightControl.KBCorePath))
{
try
{
Keyboard_Core = Assembly.LoadFile(LenovoBacklightControl.KBCorePath);
kbcver = FileVersionInfo.GetVersionInfo(LenovoBacklightControl.KBCorePath);
}
catch (Exception e)
{
Expand All @@ -37,10 +49,32 @@ public void ActivateBacklight(int lightValue)
KCInstance = Activator.CreateInstance(AssemblyType);

//get internal method info for changing the KB Backlight status
var setKeyboardBackLightStatusInfo = GetRuntimeMethodsExt(AssemblyType, "SetKeyboardBackLightStatus");

object[] lightLevel = { lightValue };
var output = (UInt32)setKeyboardBackLightStatusInfo.Invoke(KCInstance, lightLevel);
try
{
object[] lightLevel = { };
var setKeyboardBackLightStatusInfo = GetRuntimeMethodsExt(AssemblyType, "SetKeyboardBackLightStatus");
if (kbcver.FileVersion == "2.0.0.15")
{
//set with new method
HidKbdData hkbData = null;
object[] llObjects = { lightValue, hkbData };
lightLevel = llObjects;
}
else
{
//set with old method
object[] llObjects = { lightValue };
lightLevel = llObjects;
}
var output = (UInt32)setKeyboardBackLightStatusInfo.Invoke(KCInstance, lightLevel);
}
catch (Exception e)
{
const string error = "Unable to load Keyboard_Core.dll. Service will stop.";
EventLog.WriteEntry("LenovoBacklightControl", error, EventLogEntryType.Error, 50917);
LenovoBacklightControl.WriteToDebugLog(error);
LenovoBacklightControl.LBCServiceBase.Stop();
}
}

private Assembly Keyboard_Core;
Expand Down
3 changes: 2 additions & 1 deletion LBCService/LBCService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<OutputType>WinExe</OutputType>
<RootNamespace>LBCService</RootNamespace>
<AssemblyName>LBCService</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
8 changes: 8 additions & 0 deletions LBCService/LenovoBacklightControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public partial class LenovoBacklightControl : ServiceBase

public LenovoBacklightControl()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

InitializeComponent();
DebugMode();
DebugLogPath = AppDomain.CurrentDomain.BaseDirectory + "DebugLog.txt";
Expand Down Expand Up @@ -127,5 +129,11 @@ protected override void OnStop()
NamedPipeThread.Join();
WriteToDebugLog("Stop complete.");
}

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// Log the exception, display it, etc
Debug.WriteLine((e.ExceptionObject as Exception).Message);
}
}
}
Loading

0 comments on commit 286ac72

Please sign in to comment.