Hi,
I've been trying to access a resource within the shell32.dll and have been
having a bear of a time getting the information I need.
I've been doing some searching and messing with some code to do what I want,
but it doesn't seem to want to comply :).
I write the memory stream to a file and then read the file into a buffer
(because for some reason it doesn't want to let me read directly from the
stream into a buffer) and then put the buffer into a str which I can clearly
see has a decent amount of characters. Still, when I try to put the string
into a memo field it shows up as blank (I'm assuming because of one of the
funky characters at the start).
I need to do this so that it is compatible with older Windows OS like Win98.
I'm sure that I'm missing something simple here as well because I have seen
other utilities out there that are able to not only display the information,
but display it in a clean manner.
Here is the code in question :
procedure TForm1.Button1Click(Sender: TObject);
var
dllHandle : THandle;
dlgHandle : THandle;
dataHandle : THandle;
dlgPData : Pointer;
dlgDataStream : TMemoryStream;
buffer : PChar;
i,
bufferLen : Integer;
iFileHandle : Integer;
iFileLength : Integer;
iBytesRead : Integer;
tempChar : Char;
tempStr : String;
begin
dllHandle := LoadLibrary('shell32.dll');
try
if dllHandle <> 0 then
begin
dlgHandle := FindResource(dllHandle,'#1095',RT_DIALOG);
if dlgHandle <> 0 then
begin
bufferLen := SizeOfResource(dllHandle,dlgHandle);
dataHandle := LoadResource(dllHandle, dlgHandle);
if dataHandle <> 0 then
begin
try
dlgPData := LockResource(dataHandle);
if assigned(dlgPData) then
begin
dlgDataStream := TMemoryStream.Create;
try
dlgDataStream.Write(dlgPData^, bufferLen);
dlgDataStream.Seek(0, soFromBeginning);
dlgDataStream.SaveToFile('Resource_1095.txt');
try
iFileHandle := FileOpen('Resource_1095.txt',
fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
Buffer := PChar(AllocMem(iFileLength));
iBytesRead := FileRead(iFileHandle, Buffer^,
iFileLength);
FileClose(iFileHandle);
for i:=0 to iBytesRead-1 do
begin
tempChar := Buffer[i];
if (tempChar in ['A' .. 'Z','a' .. 'z',#0 ..
#31]) then
tempStr := tempStr+tempChar;
end;
memo1.Text := tempStr;
finally
FreeMem(Buffer);
end;
finally
dlgDataStream.Free;
dlgDataStream := nil;
end;
end;
finally
freeResource(dataHandle);
end;
end;
end;
end;
finally
FreeLibrary(Handle);
end;
end;
TIA for any help.
Regards,
Daniel