type
TmcCharArray = array of AnsiChar;
procedure SaveStringToFile(FileName, SourceString : string);
const
fmShareExclusive = $0010;
var
Stream : TFileStream;
begin
Stream:= TFileStream.Create(FileName, fmCreate, fmShareExclusive);
try
Stream.WriteBuffer(PChar(SourceString)^, Length(SourceString));
finally
Stream.Free;
end;
end;
function SaveInternetObjectToStringA(ObjURL: string; OutString: PChar): DWORD; stdcall;
const
MaxCount = 255;
var
s: string;
begin
ZeroMemory(OutString, MaxCount);
s := GetInternetObject(ObjURL);
if Length(s) > MaxCount then SetLength(s, MaxCount);
StrPCopy(OutString, s);
Result := StrLen(OutString);
end;
function SaveInternetObjectToFileA(ObjURL, FileName: string): boolean; stdcall;
var
s: string;
begin
s := GetInternetObject(ObjURL);
Result := Length(s) > 0;
if Result then SaveStringToFile(FileName, s);
end;
function GetInternetObject(const ObjURL: string): string;
const
tmpBuffSize = 1024;
var
hSession, hURL: HInternet;
tmpBuff: array [0..tmpBuffSize - 1] of Byte;
Buff: TmcCharArray;
ReededSize: DWORD;
BuffLen: DWORD;
begin
Result := '';
hSession := InternetOpen('InetUtils', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if not Assigned(hSession) then Exit;
hURL := InternetOpenURL(hSession, PChar(ObjURL), nil, 0, 0, 0);
if not Assigned(hURL) then begin
InternetCloseHandle(hSession);
Exit;
end;
SetLength(Buff, 0);
repeat
InternetReadFile(hURL, @tmpBuff, SizeOf(tmpBuff), ReededSize);
BuffLen := Length(Buff);
SetLength(Buff, BuffLen + ReededSize);
Move(tmpBuff[0], Buff[BuffLen], ReededSize);
until ReededSize = 0;
Result := ArrayToString(Buff);
InternetCloseHandle(hURL);
InternetCloseHandle(hSession);
end;