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,60 +171,62 @@ namespace OpenHardwareMonitor.Hardware.ATI {
public static ADL_Overdrive5_FanSpeedInfo_GetDelegate
ADL_Overdrive5_FanSpeedInfo_Get;
private static string GetDllName() {
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 string dllName;
private static void GetDelegate<T>(string entryPoint, out T newDelegate)
where T : class
{
DllImportAttribute attribute = new DllImportAttribute(GetDllName());
DllImportAttribute attribute = new DllImportAttribute(dllName);
attribute.CallingConvention = CallingConvention.StdCall;
attribute.PreserveSig = true;
attribute.EntryPoint = entryPoint;
PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
}
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",
out _ADL_Main_Control_Create);
GetDelegate("ADL_Adapter_AdapterInfo_Get",
out _ADL_Adapter_AdapterInfo_Get);
GetDelegate("ADL_Main_Control_Destroy",
out ADL_Main_Control_Destroy);
GetDelegate("ADL_Adapter_NumberOfAdapters_Get",
out ADL_Adapter_NumberOfAdapters_Get);
GetDelegate("ADL_Adapter_ID_Get",
out ADL_Adapter_ID_Get);
GetDelegate("ADL_Adapter_Active_Get",
out ADL_Adapter_Active_Get);
GetDelegate("ADL_Overdrive5_CurrentActivity_Get",
out ADL_Overdrive5_CurrentActivity_Get);
GetDelegate("ADL_Overdrive5_Temperature_Get",
out ADL_Overdrive5_Temperature_Get);
GetDelegate("ADL_Overdrive5_FanSpeed_Get",
out ADL_Overdrive5_FanSpeed_Get);
GetDelegate("ADL_Overdrive5_FanSpeedInfo_Get",
out ADL_Overdrive5_FanSpeedInfo_Get);
}
static ADL() {
GetDelegate("ADL_Main_Control_Create",
out _ADL_Main_Control_Create);
GetDelegate("ADL_Adapter_AdapterInfo_Get",
out _ADL_Adapter_AdapterInfo_Get);
GetDelegate("ADL_Main_Control_Destroy",
out ADL_Main_Control_Destroy);
GetDelegate("ADL_Adapter_NumberOfAdapters_Get",
out ADL_Adapter_NumberOfAdapters_Get);
GetDelegate("ADL_Adapter_ID_Get",
out ADL_Adapter_ID_Get);
GetDelegate("ADL_Adapter_Active_Get",
out ADL_Adapter_Active_Get);
GetDelegate("ADL_Overdrive5_CurrentActivity_Get",
out ADL_Overdrive5_CurrentActivity_Get);
GetDelegate("ADL_Overdrive5_Temperature_Get",
out ADL_Overdrive5_Temperature_Get);
GetDelegate("ADL_Overdrive5_FanSpeed_Get",
out ADL_Overdrive5_FanSpeed_Get);
GetDelegate("ADL_Overdrive5_FanSpeedInfo_Get",
out ADL_Overdrive5_FanSpeedInfo_Get);
CreateDelegates("atiadlxx");
}
private ADL() { }
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) {

View File

@@ -1,4 +1,4 @@
/*
/*
Version: MPL 1.1/GPL 2.0/LGPL 2.1
@@ -54,55 +54,59 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
return;
ManagementObjectCollection collection = new ManagementObjectSearcher(
"root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
byte[] raw = null;
foreach (ManagementObject mo in collection) {
raw = (byte[])mo["SMBiosData"];
break;
}
List<Structure> structureList = new List<Structure>();
if (raw != null && raw.Length > 0) {
int offset = 0;
byte type = raw[offset];
while (offset < raw.Length && type != 127) {
type = raw[offset]; offset++;
int length = raw[offset]; offset++;
ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]);
offset += 2;
byte[] data = new byte[length];
Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;
List<string> stringsList = new List<string>();
if (raw[offset] == 0)
offset++;
while (raw[offset] != 0) {
StringBuilder sb = new StringBuilder();
while (raw[offset] != 0) {
sb.Append((char)raw[offset]); offset++;
try {
ManagementObjectCollection collection = new ManagementObjectSearcher(
"root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
byte[] raw = null;
foreach (ManagementObject mo in collection) {
raw = (byte[])mo["SMBiosData"];
break;
}
if (raw != null && raw.Length > 0) {
int offset = 0;
byte type = raw[offset];
while (offset < raw.Length && type != 127) {
type = raw[offset]; offset++;
int length = raw[offset]; offset++;
ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]);
offset += 2;
byte[] data = new byte[length];
Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;
List<string> stringsList = new List<string>();
if (raw[offset] == 0)
offset++;
while (raw[offset] != 0) {
StringBuilder sb = new StringBuilder();
while (raw[offset] != 0) {
sb.Append((char)raw[offset]); offset++;
}
offset++;
stringsList.Add(sb.ToString());
}
offset++;
stringsList.Add(sb.ToString());
}
offset++;
switch (type) {
case 0x00:
this.biosInformation = new BIOSInformation(
type, handle, data, stringsList.ToArray());
structureList.Add(this.biosInformation); break;
case 0x02: this.baseBoardInformation = new BaseBoardInformation(
type, handle, data, stringsList.ToArray());
structureList.Add(this.baseBoardInformation); break;
default: structureList.Add(new Structure(
type, handle, data, stringsList.ToArray())); break;
switch (type) {
case 0x00:
this.biosInformation = new BIOSInformation(
type, handle, data, stringsList.ToArray());
structureList.Add(this.biosInformation); break;
case 0x02: this.baseBoardInformation = new BaseBoardInformation(
type, handle, data, stringsList.ToArray());
structureList.Add(this.baseBoardInformation); break;
default: structureList.Add(new Structure(
type, handle, data, stringsList.ToArray())); break;
}
}
}
}
} catch (NotImplementedException) { }
table = structureList.ToArray();
}