Fixed ADL dll loading. The name of the dll is always atiadlxx, except when running as 32-bit app on 64-bit systems (atiadlxy in that case).

This commit is contained in:
Michael Möller
2010-01-29 19:20:44 +00:00
parent 8fc7a41776
commit 7a48707225
2 changed files with 89 additions and 83 deletions

View File

@@ -171,34 +171,25 @@ namespace OpenHardwareMonitor.Hardware.ATI {
public static ADL_Overdrive5_FanSpeedInfo_GetDelegate public static ADL_Overdrive5_FanSpeedInfo_GetDelegate
ADL_Overdrive5_FanSpeedInfo_Get; ADL_Overdrive5_FanSpeedInfo_Get;
private static string GetDllName() { private static string dllName;
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
if (IntPtr.Size == 4) {
return "atiadlxy.so";
} else {
return "atiadlxx.so";
}
} else {
if (IntPtr.Size == 4) {
return "atiadlxy.dll";
} else {
return "atiadlxx.dll";
}
}
}
private static void GetDelegate<T>(string entryPoint, out T newDelegate) private static void GetDelegate<T>(string entryPoint, out T newDelegate)
where T : class where T : class
{ {
DllImportAttribute attribute = new DllImportAttribute(GetDllName()); DllImportAttribute attribute = new DllImportAttribute(dllName);
attribute.CallingConvention = CallingConvention.StdCall; attribute.CallingConvention = CallingConvention.StdCall;
attribute.PreserveSig = true; attribute.PreserveSig = true;
attribute.EntryPoint = entryPoint; attribute.EntryPoint = entryPoint;
PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate); PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
} }
static ADL() { private static void CreateDelegates(string name) {
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
dllName = name + ".so";
else
dllName = name + ".dll";
GetDelegate("ADL_Main_Control_Create", GetDelegate("ADL_Main_Control_Create",
out _ADL_Main_Control_Create); out _ADL_Main_Control_Create);
GetDelegate("ADL_Adapter_AdapterInfo_Get", GetDelegate("ADL_Adapter_AdapterInfo_Get",
@@ -221,10 +212,21 @@ namespace OpenHardwareMonitor.Hardware.ATI {
out ADL_Overdrive5_FanSpeedInfo_Get); out ADL_Overdrive5_FanSpeedInfo_Get);
} }
static ADL() {
CreateDelegates("atiadlxx");
}
private ADL() { } private ADL() { }
public static int ADL_Main_Control_Create(int enumConnectedAdapters) { public static int ADL_Main_Control_Create(int enumConnectedAdapters) {
return _ADL_Main_Control_Create(Main_Memory_Alloc, enumConnectedAdapters); try {
return _ADL_Main_Control_Create(Main_Memory_Alloc,
enumConnectedAdapters);
} catch (DllNotFoundException) {
CreateDelegates("atiadlxy");
return _ADL_Main_Control_Create(Main_Memory_Alloc,
enumConnectedAdapters);
}
} }
public static int ADL_Adapter_AdapterInfo_Get(ADLAdapterInfo[] info) { public static int ADL_Adapter_AdapterInfo_Get(ADLAdapterInfo[] info) {

View File

@@ -1,4 +1,4 @@
/* /*
Version: MPL 1.1/GPL 2.0/LGPL 2.1 Version: MPL 1.1/GPL 2.0/LGPL 2.1
@@ -55,6 +55,9 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
if ((p == 4) || (p == 128)) if ((p == 4) || (p == 128))
return; return;
List<Structure> structureList = new List<Structure>();
try {
ManagementObjectCollection collection = new ManagementObjectSearcher( ManagementObjectCollection collection = new ManagementObjectSearcher(
"root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get(); "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
@@ -64,7 +67,6 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
break; break;
} }
List<Structure> structureList = new List<Structure>();
if (raw != null && raw.Length > 0) { if (raw != null && raw.Length > 0) {
int offset = 0; int offset = 0;
byte type = raw[offset]; byte type = raw[offset];
@@ -103,6 +105,8 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
} }
} }
} }
} catch (NotImplementedException) { }
table = structureList.ToArray(); table = structureList.ToArray();
} }