尝试与 AMD ADL 库 (DLL) 交互以检索显卡上的信息。有一些功能可以工作,但有问题。
请看这篇有同样问题但没有答案的帖子:ATI ADL - AdapterInfo_Get
该函数使用 delphi 数组返回,但内容错误。
该函数使用指向缓冲区的指针返回,但数据相同[错误]。
[参见下面的代码示例]
该函数在文档中定义如下:
int ADL_Adapter_AdapterInfo_Get(LPAdapterInfo lpInfo, int iInputSize)
Retrieves all OS-known adapter information.
This function retrieves the adapter information of all OS-known adapters in the
system. OS-known adapters can include adapters that are physically present in the
system (logical adapters) as well as ones that are no longer present in the system
but are still recognized by the OS.
Supported Platforms:
Linux and Windows(XP, Vista and Windows 7); 32bit and 64bit
Parameters:
[in] iInputSize The size of the lpInfo buffer.
[out] lpInfo The pointer to the buffer containing the retrieved adapter information.
Returns:
If the function succeeds, the return value is ADL_OK. Otherwise the return value is an ADL error code. Result Codes
Remarks:
This API take a fixed-size output array. For dynamic-size output, use ADL_Adapter_AdapterInfoX2_Get function.
adl_structures.pas 文件定义 AdapterInfo 如下:
AdapterInfo = record
iSize : integer;
iAdapterIndex : integer;
strUDID : array [0..ADL_MAX_PATH] of char;
iBusNumber : integer;
iDeviceNumber : integer;
iFunctionNumber : integer;
iVendorID : integer;
strAdapterName : array [0..ADL_MAX_PATH] of char;
strDisplayName : array [0..ADL_MAX_PATH] of char;
iPresent : integer;
{$IFDEF MSWINDOWS}
iExist : Integer;
strDriverPath : array [0..ADL_MAX_PATH-1] of Char;
strDriverPathExt : array[0..ADL_MAX_PATH-1] of Char;
strPNPString : array[0..ADL_MAX_PATH-1] of char;
iOSDisplayIndex : integer;
{$ENDIF} { (_WIN32) || (_WIN64) }
end;
LPAdapterInfo = ^AdapterInfo;
我以这种方式为每个函数声明了一个类型:
type
TADL_MAIN_CONTROL_CREATE = function(param1 : ADL_MAIN_MALLOC_CALLBACK; param2 : integer) : integer; cdecl;
TADL_MAIN_CONTROL_DESTROY = function : integer; cdecl;
TADL_OVERDRIVE5_TEMPERATURE_GET = function (iAdapterIndex, iThermalControllerIndex : integer; var lpTemperature : ADLTemperature) : integer; cdecl;
TADL_OVERDRIVE5_FANSPEED_GET = function (iAdapterIndex, iThermalControllerIndex: integer; var lpFanSpeedValue: ADLFanSpeedValue): integer; cdecl;
TADL_ADAPTER_NUMBEROFADAPTERS_GET = function (var lpNumAdapters: integer): integer; cdecl;
TADL_ADAPTER_ACTIVE_GET = function(iAdapterIndex: integer; var lpStatus: Integer): Integer; cdecl;
TADL_ADAPTER_ADAPTERINFO_GET = function(AInfo : Pointer; iInputSize: Integer): integer; cdecl;{stdcall;}
以这种方式创建变量:
var
ADL_Overdrive5_Temperature_Get : TADL_OVERDRIVE5_TEMPERATURE_GET;
ADL_Adapter_NumberOfAdapters_Get : TADL_ADAPTER_NUMBEROFADAPTERS_GET;
ADL_Adapter_Active_Get : TADL_ADAPTER_ACTIVE_GET;
ADL_Adapter_AdapterInfo_Get : TADL_ADAPTER_ADAPTERINFO_GET;
ADL_Overdrive5_FanSpeed_Get : TADL_OVERDRIVE5_FANSPEED_GET;
temperature : ADLTemperature;
fanspeed : ADLFanSpeedValue;
numGFX, numActiveGFX : Integer;
GFXActive : Integer;
x, size : integer;
ADL_Info : AdapterInfo;
ADL_PInfo : LPAdapterInfo;
ADL_AInfo : Array of AdapterInfo;
ADL_Result : Integer;
ActiveAdapters : Array of Integer;
Addr : Pointer;
strPresent : String;
以这种方式链接到外部函数:
ADL_Adapter_NumberOfAdapters_Get := GetProcAddress(hDLL, 'ADL_Adapter_NumberOfAdapters_Get');
ADL_Overdrive5_Temperature_Get := GetProcAddress(hDLL, 'ADL_Overdrive5_Temperature_Get');
ADL_Adapter_Active_Get := GetProcAddress(hDLL, 'ADL_Adapter_Active_Get');
ADL_Adapter_AdapterInfo_Get := GetProcAddress(hDLL, 'ADL_Adapter_AdapterInfo_Get');
ADL_Overdrive5_Fanspeed_Get := GetProcAddress(hDLL, 'ADL_Overdrive5_FanSpeed_Get');
然后我尝试将数据放入一个数组并放入一个内存缓冲区。两者都返回完全相同的数据,但它无效。请注意,其他功能正在运行或返回有效错误,例如“驱动程序不支持”。
大批:
if Assigned(ADL_Adapter_AdapterInfo_Get) then
begin
//*** Array (delphi way)
Setlength(ADL_AInfo, numGFX);
Addr := ADL_AInfo;
size := sizeof(AdapterInfo)*numGFX;
try
ADL_Result := ADL_Adapter_AdapterInfo_Get(Addr, size);
If ADL_Result = ADL_OK then
begin
for x := 0 to numGFX-1 do
begin
//using a delphi array
Memo1.Lines.Add('Vender ID for Adapter Index '+IntToStr(ADL_AInfo[x].iAdapterIndex)+' is '+IntToStr(ADL_AInfo[x].iVendorID));
Memo1.Lines.Add('Device Number for Adapter Index '+IntToStr(ADL_AInfo[x].iAdapterIndex)+' is '+IntToStr(ADL_AInfo[x].iDeviceNumber));
Memo1.Lines.Add('Adatper Name for Adapter Index '+IntToStr(ADL_AInfo[x].iAdapterIndex)+' is '+ADL_AInfo[x].strAdapterName);
Memo1.Lines.Add('Display Name for Adapter Index '+IntToStr(ADL_AInfo[x].iAdapterIndex)+' is '+ADL_aInfo[x].strDisplayName);
if ADL_AInfo[x].iPresent = 0 then strPresent := 'not present' else strPresent := 'present';
Memo1.Lines.Add('Adapter Index '+IntToStr(ADL_AInfo[x].iAdapterIndex)+' is '+strPresent);
end;
end
else
Memo1.Lines.Add('Error : '+IntToStr(ADL_Result));
finally
end;
end;
内存缓冲区:
if Assigned(ADL_Adapter_AdapterInfo_Get) then
begin
//*** Pointer (c lookalike)
size := sizeof(AdapterInfo)*numGFX;
//GetMem(ADL_PInfo, size);
ADL_PInfo := AllocMem(sizeof(AdapterInfo) * numGFX);
try
ADL_Result := ADL_Adapter_AdapterInfo_Get(ADL_PInfo, size);
If ADL_Result = ADL_OK then
begin
for x := 0 to numGFX-1 do
begin
//using getmem with a pointer to a record
Memo1.Lines.Add('Vender ID for Adapter Index '+IntToStr(ADL_PInfo.iAdapterIndex)+' is '+IntToStr(ADL_PInfo.iVendorID));
Memo1.Lines.Add('Device Number for Adapter Index '+IntToStr(ADL_PInfo.iAdapterIndex)+' is '+IntToStr(ADL_PInfo.iDeviceNumber));
Memo1.Lines.Add('Adatper Name for Adapter Index '+IntToStr(ADL_PInfo.iAdapterIndex)+' is '+ADL_PInfo.strAdapterName);
Memo1.Lines.Add('Display Name for Adapter Index '+IntToStr(ADL_PInfo.iAdapterIndex)+' is '+ADL_PInfo.strDisplayName);
if ADL_PInfo.iPresent = 0 then strPresent := 'not present' else strPresent := 'present';
Memo1.Lines.Add('Adapter Index '+IntToStr(ADL_PInfo.iAdapterIndex)+' is '+strPresent);
inc(ADL_Pinfo);
end;
end
else
Memo1.Lines.Add('Error : '+IntToStr(ADL_Result));
finally
// ZeroMemory(ADL_PInfo, size);
end;
end;