delphi调用AMD ADL c ++ dll [英] delphi calling AMD ADL c++ dll

查看:133
本文介绍了delphi调用AMD ADL c ++ dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试与AMD ADL库(DLL)交互以检索图形卡上的信息。有一些功能可以使用,但是有问题。

请参阅相同的问题但无答案的帖子: ATI ADL-AdapterInfo_Get

Trying to interface with AMD ADL library (DLL) to retrieve info on the graphics card. Got some of the functions to work but having problems.

Pls see this post with same question but no answer: ATI ADL - AdapterInfo_Get

该函数使用delphi数组返回,但内容错误。

该函数使用指向缓冲区的指针返回,但数据相同[错误]。

[请参见下面的代码示例]

The function returns using a delphi array but the content is wrong.
The function returns using a pointer to a buffer but the data is the same [wrong].
[see below for code example]

该功能在文档中定义如下:

The function is defined in the documentation as follows:

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定义如下:
类型

The adl_structures.pas file defines AdapterInfo as follows: type

  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;

我为每个函数声明了一种类型:

I declared a type for each function this way:

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;}

通过以下方式创建变量:

Created variables this way:

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;

通过以下方式链接到外部功能:

Linking to external functions this way:

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');

然后我尝试将数据放入数组和内存缓冲区。两者都返回完全相同的数据,但无效。请注意,其他函数正在运行或返回有效错误,例如驱动程序不支持。

I then try to get the data into an array and into a memory buffer. Both return the exact same data but its not valid. Note that the other functions are working or return valid errors such as "not supported by driver".

Array:

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;


推荐答案

解决方案很简单。


  1. 下载PRAXIS库

  2. 在文件 adl_structures.pas中查找所有Char实例,并将其更改为AnsiChar

  3. 在同一文件中,查找 [0..MAX_PATH]的所有实例并将其更改为 [0..MAX_PATH-1]

上面获得指向DLL中的函数的指针并提取数据的代码是有效的并且可以正常工作

The code above to get the pointers to the functions in the DLL and extract data is valid and works fine

这篇关于delphi调用AMD ADL c ++ dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆