AMD ADL ライブラリ (DLL) と連携して、グラフィック カードの情報を取得しようとしています。一部の機能は動作しますが、問題があります。
Pls は、同じ質問が回答のないこの投稿を参照してください: 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;