1,184
社区成员
发帖
与我相关
我的任务
分享
var
i, iSize: Integer;
SourceId: Cardinal;
szValue1: PChar;//array[0..MAX_PATH - 1] of Char;
szValue2: PChar;//array[0..MAX_PATH - 1] of Char;
sValue1, sValue2: string;
begin
iSize := MAX_PATH * SizeOf(Char);
szValue1 := GetMemory(MAX_PATH * SizeOf(Char));
szValue2 := GetMemory(MAX_PATH * SizeOf(Char));
try
for i := 0 to AList.Count - 1 do
begin
ZeroMemory(szValue1, iSize);
if SetupGetSourceFileLocation(AInf, nil, PChar(AList.Strings[i]),
SourceId, szValue1, MAX_PATH, nil) then
begin
// sValue1 := szValue1;
SetLength(sValue1, lstrlen(szValue1));
CopyMemory(@sValue1[1], szValue1, lstrlen(szValue1) * SizeOf(Char));
ZeroMemory(szValue2, iSize);
if SetupGetSourceInfo(AInf, SourceId, SRCINFO_PATH, szValue2,
MAX_PATH, nil) then
begin
// sValue2 := szValue2;
//第二次循环时,此处报错,不管是直接赋值还是用CopyMemory,字符szValue为Char数组和PChar都试过。
SetLength(sValue2, lstrlen(szValue2));
CopyMemory(@sValue2[1], szValue2, lstrlen(szValue2) * SizeOf(Char));
end
else
szValue2 := '';
OutputDebugString(PChar(sValue2 + '\' + sValue1));
end;
end;
finally
FreeMemory(szValue1);
FreeMemory(szValue2);
end;
end;
sValue := szValue + #0;
if Result.IndexOf(sValue) = -1 then
Result.Add(sValue);
SetLength(sValue, lstrlen(szValue) + 2);
CopyMemory(@sValue[1], szValue, lstrlen(szValue) * SizeOf(Char));
if Result.IndexOf(sValue) = -1 then
Result.Add(sValue);
sValue := StrPas(szValue);
OutputDebugString(PChar(sValue));
function GetSections(AInf: HINF): TStrings;
var
szValue: PChar;
sValue: string;
i, iSize: Integer;
begin
Result := TStringList.Create;
iSize := MAX_PATH * SizeOf(Char);
szValue := StrAlloc(iSize);
try
ZeroMemory(szValue, iSize);
i := 0;
if SetupEnumInfSections(AInf, i, szValue, iSize, nil) then
repeat
if GetLastError = ERROR_NO_MORE_ITEMS then
Break;
//这里加上#0就不报错了,但其它地方不行(如调用SetupGetStringField之后),见鬼
// sValue := szValue + #0;
sValue := StrPas(szValue);
OutputDebugString(PChar(sValue));
//这里多分配一个Char也好了,又见鬼
// SetLength(sValue, lstrlen(szValue) + SizeOf(Char));
// CopyMemory(@sValue[1], szValue, lstrlen(szValue) * SizeOf(Char));
//下面两句去掉,也不报错了,真见鬼了
if Result.IndexOf(sValue) = -1 then
Result.Add(sValue);
Inc(i);
ZeroMemory(szValue, iSize);
until not SetupEnumInfSections(AInf, i, szValue, iSize, nil);
finally
StrDispose(szValue);
end;
end;