我正在尝试从GPU-Z共享内存中读取信息,但我做错了。我已设法翻译TechPowerUp论坛上发布的共享内存结构。我可以阅读所有GPUZ_RECORD
但不能阅读GPUZ_SENSOR_RECORD
。任何帮助都会被贬低。谢谢!
稍后编辑我:
如果我使用packet record
而不再使用AV,但我仍然无法获取传感器信息。
LATER EDIT II:
如果我从0到128(129个元素)读取data
,那么128元素是第一个传感器,我可以正确地看到数据。 :(
const
MAX_RECORDS = 128;
GPUZ_RECORD = record
key: array[0..255] of WChar;
value: array[0..255] of WChar;
end;
GPUZ_SENSOR_RECORD = record
name: array[0..255] of WChar;
units: array[0..7] of WChar;
digits: Cardinal;
value: double;
end;
GPUZ_SH_MEM = record
version : Cardinal;
busy: Boolean;
lastUpdate: Cardinal;
data: array [0..MAX_RECORDS] of GPUZ_RECORD;
sensors: array [0..MAX_RECORDS] of GPUZ_SENSOR_RECORD;
end;
PGPUZ_SH_MEM = ^GPUZ_SH_MEM;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
procedure TMainForm.readSensors;
var
hMapFile: Thandle;
sKey, sVal: string;
GPUInfo: PGPUZ_SH_MEM;
s, d: integer;
begin
hMapFile := OpenFileMapping(FILE_MAP_READ, FALSE, 'GPUZShMem');
if hMapFile <> 0 then begin
log(['Mapping succesfully']);;
GPUInfo := MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
// ShowMessage(IntToStr(GetLastError));
if GPUInfo <> nil then begin
log([ GPUInfo^.version ]);
log([ GPUInfo^.busy ]);
log([ GPUInfo^.lastUpdate ]);
log(['LOGING DATA ~~~~~~~~~~~~~~~~~~~~~~']);
for d:= 0 to Pred(MAX_RECORDS) do begin
sKey := GPUInfo^.data[d].key;
sVal := GPUInfo^.data[d].value;
if sKey <> '' then log([d, '#: ', sKey, sVal ]);
end;
log(['LOGING SENSORS ~~~~~~~~~~~~~~~~~~~~']);
for s:= 0 to Pred(MAX_RECORDS) do begin
sKey := GPUInfo^.sensors[s].name; // i get an AV here when s:=127
log([ 'Sensor ', s, '#: ', sKey ]);
// sVal := TPN^.sensors[s].units;
// log([ 'Unit: ', sVal ]);
// log(['Digits: ', TPN^.sensors[s].digits ]);
// log(['Value: ', TPN^.sensors[s].value ]);
end;
end else log([ 'Could not map that zone!' ]);
end else begin
log(['Could not find the zone for mapping...']);
UnmapViewOfFile(GPUInfo);
CloseHandle(hMapFile);
end;
end;
log()是一个像这样定义的小程序:
procedure log( vData: array of Variant );
答案 0 :(得分:0)
这很可能是结构对齐或pascal API / struct转换问题。您是否在C中检查了SizeOf(GPUZ_SENSOR_RECORD)并查看它是否与pascal中的sizeof(GPUZ_SENSOR_RECORD)匹配?你尝试过更改对齐吗?
答案 1 :(得分:0)
const
MAX_RECORDS = 127; // <-- important [0..127] => 128 elements
GPUZ_RECORD = packed record // <-- all records must be packed
key: array[0..255] of WChar;
value: array[0..255] of WChar;
end;
GPUZ_SENSOR_RECORD = packed record // <-- all records must be packed
name: array[0..255] of WChar;
units: array[0..7] of WChar;
digits: Cardinal;
value: double;
end;
GPUZ_SH_MEM = packed record // <-- all records must be packed
version : Cardinal;
busy: Boolean;
lastUpdate: Cardinal;
data: array [0..MAX_RECORDS] of GPUZ_RECORD;
sensors: array [0..MAX_RECORDS] of GPUZ_SENSOR_RECORD;
end;
PGPUZ_SH_MEM = ^GPUZ_SH_MEM;