Avatar Zondertau wrote on 11/23/2004 06:09 PST:
Quote
>I extracted a cursor from a resource and saved it using the
>following code:
>
>The output isn't a valid cursor file thought. What am I doing wrong?
You're not using the TResourceStream class, which is useful for loading
resources. Are you doing this on purpose? If not so you could use it
instead of the API calls, which would also be more readable and
maintainable.
I'd tried TResourceStream before in combination with Cursor
and without, using this code:
function TForm1.ExtractCursorToDir(const Lib: HMODULE;
ResName: string; const OutputDir: string): Boolean;
var
ResStream: TResourceStream;
Stream: TFileStream;
Cursor: TIcon;
begin
if FindResource(Lib, PChar(ResName), RT_CURSOR) <>0 then
try
ResStream := TResourceStream.Create(Lib, ResName, RT_CURSOR);
try
Cursor := TIcon.Create;
try
ResStream.Position := 0;
Cursor.LoadFromStream(ResStream);
ResName := LowerCase(Copy(ResName, Pos('#', ResName) + 1,
Length(ResName)));
// Stream := TFileStream.Create(OutPutDir + ResName + '.cur',
fmCreate);
try
Cursor.SaveToFile(OutPutDir + ResName + '.cur');
// Stream.CopyFrom(ResStream, ResStream.Size);
Result := TRUE;
finally
// Stream.Free;
end;
finally
Cursor.Free;
end;
finally
ResStream.Free;
end;
except
Result := FALSE;
end
else
Result := FALSE;
end;
The result was the same.
Quote
I can not really see a bug in your code. Does the cursor resource work if
you use LoadCursor? What are the differences between the original CUR
file and the resource (you could use a hexeditor or a file compar
utility, like "fc" on the command line, to find these)?
Comparing it with the correct cursor file shows a difference
of 18 bytes, and what's missing is the header part. Only the
actual cursor picture is in the file.
If tried LoadCursor too, but I only get 0 as result. The cursor
in the resource doesn't have a name but an ID. I don't know if
this is the reason.
It works fine with all other WinAPI calls though.
Thank you for trying to help.
--
Norma